how to edit and update a filed in a sublist of a record in netsuite thought script?

2.7k views Asked by At

Have to update a transaction record(upto 2000 records) in netsuite through script. In Netsuite, need to update a field in transaction record(order/return) line item. As its massive update thought to update through scripts.

Is it possible to do with creating a scirpt and deploying as restlet and processing all the records and update it?

3

There are 3 answers

0
Adolfo Garza On

You couldn't do it as a RESTlet because you would run out of governance points or your request would time out.

I suggest doing this through a Map/Reduce script/scheduled script/Mass update script.

0
B. Assem On

Like you said, it is a massive update, so the best solution is to create a Mass Update script that you can schedule to run once a day for example.

2
Luke Pirtle On

A map/reduce would be ideal but a scheduled script is probably good enough and will be easier. You may have to reschedule it

if (nlapiGetContext().getRemainingUsage() < SizeNeededToProcessTransaction) {
    nlapiYieldScript();
} 
// process transaction

You'll be dealing with sublists so you can't do a direct update through script, you'll have to load the record, update the line, commit the line and then save the record. I have a simple example below to give you an idea of how to do this. I'm assuming you're updating every line on a custom field on the item sublist in this example

var r = nlapiLoadRecord('transaction', internalid); // load transaction

var count = nlapiGetLineItemCount('item'); // get number of lines in sublist
for (var i = 1; i <= count; i++) { // sublists start at 1 so for loop params are different
    r.selectLineItem('item', i); // select the line item
    r.setCurrentLineItemValue('item', 'custcol_updateField', someValue); // assign the value you want 
    r.commitLineItem('item'); // commits the line 
}

nlapiSubmitRecord(r); // saves the transaction changes

I'd recommend trying out a code snippet on a test record then after it has run successfully running the rest in the scheduled script