Suitescript 2.0 update lookup field value

852 Views Asked by At

I need to get a lookup fields value from a line item on an SO and then update the corresponding line item in a PO. Fetching the value is not a problem, I'm using

newSite = record.getSublistValue("item", "custcol_site", lineNum)

to get the value - this returns the id of the lookup field object. However when I then try to update the field value on the PO using

loadedTransaction.setSublistValue({
    sublistId: "item",
    fieldId: "custcol_site",
    value: newSite,
    line: lineNum
});

Nothing happens, I don't get an error, however the field doesn't update either. How can I update the field using this ID value I've already fetched?

I'm also updating a number of other fields without issue following the same pattern, it's only the lookup field that's not updating successfully, so "lineNum" and fieldIds are not the problem as far as I can tell, I must just not be sending the correct information to update the lookup, however I can't find somewhere to tell me what information to send through.

2

There are 2 best solutions below

3
erictgrubaugh On

Inferring from the name loadedTransaction that you have called record.load() to retrieve that reference, you'll also need to then call loadedTransaction.save() to commit your changes to the database.

0
Addy On

Are you committing the line item before saving the record ? recordObj.commitLine('item');