Hi, complete newbie to suitescript.
I'm trying to populate a custom field (revMonth) on an invoice with multiple transaction lines, based on the posting period (at header level, Field ID: postingperiod) and the line item's income account code/number (Field ID: incomeaccount).
i.e. For each line on the invoice that has an item: IF item's income account number begins with '2' THEN revMonth = postingPeriod + 1 month ELSE postingPeriod
Each item has an income account number associated with it, so I assume there will be a need to do a lookup of some sort to determine what the number is. The custom field (revMonth) is currently a 'free-text' field.
The question is similar to How to populate Items Sublist Field with a Header Field value on a Purchase Order but with an IF statement involved, and the use of date fields.
Was trying to break this down into different stages, but when I copied the code from the page (with a few changes to the referenced fieldId) and tried to deploy it on invoices I get an error saying "Type error cannot read property getValue of undefined"
/*** @NApiVersion 2.x* @NScriptType ClientScript*/define(['N/record'], function (record) { function fieldChanged(context) { var getCurrentRecord = context.getCurrentRecord; var postingPeriod = getCurrentRecord.getValue({ fieldId: 'postingperiod' }); if (postingPeriod) { if (context.sublistId == 'item') { getCurrentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'custcolrevmonthtline', value: postingPeriod, ignoreFieldChange: true }); } } } return { fieldChanged: fieldChanged }});Any help would be appreciated. Thanks in advance!