Maira S
Maira S

Reputation: 47

How to avoid NetSuite record has been changed error?

I have developed scheduled script to create journal entry records for each invoice item. Now, I have created 2 functions. First function, creates journal entries for all items on invoice records. Second function, sets created journal entry record reference on invoice record's subslist.

Now I have added logic to reschedule script to avoid usage issue in first function.

If I create je and set craeted je on invoice line for 50 items batch and then reschedule the script in second function. In that case I have to save invoice record after every 50 items. I think it will error out as record has been changed. Please advice!

Please advice!

Below is pseudocode:

function execute()
{
    //Fetches data from saved search and create journal entries
    createjournals();
 
}
function createjournals()
{
    //create Journal entries
     journal.save
     if(remainingusage<100)
     {
     reschedulescript();
     }
     if(createdjearray.length>0)
     {
     updateinvoicelines();
     }
}
function updateinvoicelines()
{
    //set Journal entries references on invoice item line
    invoice.save();
}

Upvotes: 0

Views: 85

Answers (2)

cesar parra
cesar parra

Reputation: 31

Before re-scheduling the script, make sure to save the invoice and exit this avoid process the same invoice in multiple schedule script instances at the same time.

Upvotes: 1

Mohammad Talha
Mohammad Talha

Reputation: 11

When working with updateinvoicelines(), ensure you minimize the duration between loading and saving the record. Fetch the record, update only the necessary fields, and save it immediately. Add error-handling logic to retry saving the record if it fails due to a "Record has been changed" error. This can be done with a try-catch block and a retry mechanism.

Upvotes: 1

Related Questions