1
votes

I am trying to re-use a class and run it in a job to prove something out. Here is the job code:

InventQuarantineOrder_Scrap scrap = new InventQuarantineOrder_Scrap();
;

scrap.parmInventQuarantineId('00016749_077');
scrap.parmScrapQty(360);
scrap.parmTransDate(Today());

scrap.run();

When I run this code, I get the error:

The cursor is invalid for instantiating recordViewCache

Researching this error led to me this link, which I tried to implement but I got syntax errors I'm not sure how to fix. I copied the class and created a new runOnServer method. But then a validate method doesn't work. So I modify the validate method to run on the server:

static server boolean  validate()
{
     InventQuarantineOrder inventQuarantineOrder =  InventQuarantineOrder::find(inventQuarantineId);
     ;  
     ....    
}

Which gave me this error:

Variable inventQuarantineId has not been declared.

If I comment out the validate() call from the runOnServer method, I get the same error/problem with the inventQuarentineId variable not being declared (it's also used in the run method).

From here, I am not sure how to continue. What am I doing wrong? Is it possible to use these methods inside a server method? Another thing worth noting I think is that I think the job code actually worked, but it did throw 3 lines those "cursor is invalid for instantiating recordViewCache." info alerts.

1
You need to use the pack/unpack pattern to transfer the value of the variable from client to server tier. I will write up an answer on this as soon as I find the time (or someone beats me to it). - FH-Inway

1 Answers

0
votes

As you already found out, a RecordViewCache can only be used on the server tier. By starting your process in the job on the client tier, the method that creates the RecordViewCache (method viewCacheInventTransId of table InventTrans) is also executed on the client tier, which causes the error. If you put a breakpoint in this method, the call stack in the debugger shows you this:

Tier   Method                                                                                                Line
[c]    \Data Dictionary\Tables\InventTrans\Methods\viewCacheInventTransId                                      9
[c]    \Classes\InventMovement\viewCacheInventTransId                                                          7
[s]    \Classes\InventUpd_Financial\initUpdate                                                                14
[s]    \Classes\InventUpd_Financial\newVirtuelQuarantineLoss                                                  19
[c]    \Classes\InventQuarantineOrder_Scrap\run                                                               76
[c]    \Jobs\Job4  

The solution in the link you gave is for your case a bit more complicated than it needs to be (my comment was my first idea to fix this solution). You just need to create a class with a static server method that executes your job code. You can then call this static server method in your code. Now the debugger will show you the following call stack:

Tier   Method                                                                                                Line
[s]    \Data Dictionary\Tables\InventTrans\Methods\viewCacheInventTransId                                      9
[s]    \Classes\InventMovement\viewCacheInventTransId                                                          7
[s]    \Classes\InventUpd_Financial\initUpdate                                                                14
[s]    \Classes\InventUpd_Financial\newInventQuarantineOrder                                                  21
[s]    \Data Dictionary\Tables\InventQuarantineOrder\Methods\startFinancial                                   12
[s]    \Classes\InventQuarantineOrder_Scrap\run                                                               54
[s]    \Classes\Class1\jobOnServer                                                                            10
[c]    \Jobs\Job4                                                                                              5