i want to set the department of the line field as ...
# suitescript
v
i want to set the department of the line field as the department of the body field. i have below code, but it does not success. define(['N/search','N/record','N/currentRecord'], function (search,record,currentRecord) { function fieldChanged(context){ var transactionRecord = context.currentRecord; var transactionType = transactionRecord.type; var sublistName = context.sublistId; var changedField = context.fieldId; try{ if (sublistName === 'item' && changedField === 'item'){ log.debug('entering if'); var headerFieldSearch = transactionRecord.getValue('department'); log.debug('line',context.line); if(headerFieldSearch){ log.debug('setting headerfield',headerFieldSearch); transactionRecord.selectLine({ sublistId : 'item', line : context.line }); transactionRecord.setCurrentSublistValue({ sublistId : 'item', fieldId : 'department', value : headerFieldSearch //line : context.line //ignoreFieldChange : true }); log.debug('set'); transactionRecord.commitLine({ sublistId : 'item' }); log.debug('committed'); } } //transactionRecord.save(); }catch(e){log.debug('error',e);} } return{ fieldChanged : fieldChanged } } );
w
You might be using the wrong method to get the body department field for the "headerFieldSearch" variable. Also you probably don't need to select the sublist line if it is already selected and submitting the line might fail since the user has not entered a quantity or other mandatory columns.
Copy code
var value = objRecord.getValue({
    fieldId: 'department'
});
v
no it returns value, that is not the issue.
w
What sort of transaction is this client script running on?
v
all the transaction types, now on PO/
c
@vennila ramasamy If this feature doesn't require that the department is automatically set when the item is changed, can you set the department using
validateLine
instead?