Hello, is it possible to update a sublist line dir...
# suitescript
p
Hello, is it possible to update a sublist line directly with a scheduled script? I am trying the following and it is not saving the field. try { var soRecord = record.load({ type: record.Type.SALES_ORDER, id: appliedtointernalid.value }); var abc=soRecord.setSublistValue({ sublistId: 'item', fieldId: 'custcol_pi_projectforsoline', line: linenum, value: jobtoset.value }); var recId= soRecord.save(); }catch(e){ log.debug('WO '+ WOID, e.toString()); } log.debug('WO '+ recId +' is updated');
b
the code by itself looks fine, you probably want to make sure that all the variables have valid values
depending on how scripted your account is, you might want to disable other workflows or scripts that could change the value of the field
or at least create a new field that wont be affected by other customizations
p
thanks. can you go directly to the specific sublist line with a script?
b
Not sure what you mean by that
The code you have is 1 of 2 ways to modify sublist fields
The other is using dynamic mode
p
got it. what I mean is that I go directly to the transaction with my script and edit the specific line without doing the loop through all the items. I got the line number directly from a saved search
b
the code you shared has no loops
its about as direct as you will get in suitescript
p
thanks. I'll try it out tomorrow
e
i think you should be careful with the line number, and make sure whatever value you retrieved from your search (no detail was provided) you are hitting the correct/expected line. This line number is a sequenced line as opposed to Line ID or Line Unique Key. And it is 0-based. So, I am not sure you can get to it in search. You will probably need to find the right line by looping through or calling findSublistLineWithValue
p
it looks like I am able to set the correct line by doing the following var linenum = searchResult.values["GROUP(linesequencenumber.appliedToTransaction)"]-1;
thank you ec. that was the issue
e
Wow great - glad to help