Is it possible to override a line value when using...
# suitescript
m
Is it possible to override a line value when using the record.transform? I'm creating an item receipt record from a PO. However, I'd like to provide the quantity value for the line.
b
it returns a record that you can use to make changes
m
So once the Item Receipt record is created, I'd need to make changes then save the record?
b
same as record.load
f
record.transform does not persist the record initially so you can do something like myFancyNewRecord = record.transform..... and then you can do myFancyNewRecord.setValue('fieldId','value');
And then when you are all happy with your new record you can do myFancyNewRecord.save()
m
I tried this, but it gives me the following error: "*You cannot initialize itemreceipt: invalid reference 665152*" - 665152 is the poId.
Copy code
const itemReceipt = record.transform({
                   fromType: record.Type.PURCHASE_ORDER,
                   fromId: poId,
                   toType: record.Type.ITEM_RECEIPT,
                   isDynamic: true,
               });
               const lineCount = itemReceipt.getLineCount({sublistId: 'item'});
               for (let line = 0; line < lineCount; line++) {
                   itemReceipt.setSublistValue({
                       sublistId: 'item',
                       fieldId: 'quantity',
                       line: line,
                       value: 5
                   });
               }
               const itemReceiptId = itemReceipt.save();
Ah, the PO is not pending receipt, that's why. I will create some test POs in pending receipt and try the above again.