AnsweredAssumed Answered

Script behaves differently in Script Debugger

Question asked by deathrobot on Apr 22, 2014
Latest reply on Apr 23, 2014 by deathrobot

Title

Script behaves differently in Script Debugger

Post

     I have a script that duplicates an invoice record as well as its children (line items). I'm having a very strange situation where everything works fine when I use the script debugger, but the script behaves incorrectly when I trigger it normally. Basically the script:

     1) Grabs the current invoice id as a variable
     2) Duplicates the invoice
     3) Grabs the duplicate invoice id as a variable
     4) Goes to the related Lines table and finds the first invoice's children, using the variable
     5) Duplicates all these records, and resets their related ids to the duplicate invoice id

     The bold lines below are the critical ones to the problem I am experiencing. When using the script debugger, the Set Field to $idNew script step works as it should. When I trigger the script normally, the Lines::id_QuotesInvoices fields get set to a new id. I must be doing something wrong, but I'm not even sure how this possible.

     #
     # Grab the original record id and the duplicated record id
     #
     Set Variable [$idOrig; Value:QuotesInvoices::id]
     Duplicate Record/Request
Set Variable [$idNew; Value:QuotesInvoices::id]
     #
     # Duplicate child records
     #
     New Window [Name: "hidden"; Left: -5000; Style: Document
     Go to Layout ["Lines" (Lines)]
     Perform Find [Restore: Lines::id_QuotesInvoices = $idOrig]
     Unsort Records
     Go to Record/Request/Page [First]
     Set Variable [$recordPosn; Value:1]
     Set Variable [$foundCount; Value:Get ( FoundCount )]
     Loop
         Exit Loop if $recordPosn > $foundCount]
         Duplicate Record/Request
    Set Field [Lines::id_QuotesInvoices; $idNew]
         Set Variable [$recordPosn; Value$recordPosn + 1]
         Go to Record/Request/Page [No dialog; $recordPosn]
     End Loop
     Close Window [Name: "hidden"; Current file]

Outcomes