SuiteScript Auto Populate Department Line Item Fie

2019-08-18 04:10发布

问题:

Code Portion Click Here

I am trying to populate the Department line item field as per the Department Transaction Body Field, please assist to check if my codes are right.. i am new to suitescript.

var itemDepartment = nlapiGetFieldValue('department');
var nlapiSetCurrentLineItemValue = nlapiSetCurrentLineItemValue('item', 'department_display', itemDepartment);

It keeps stating that department_display is not an internal ID.

Please advise.

Thank you.

回答1:

Can you try setting text instead,if it is a client script. The id of the department column field is 'department'

var itemDepartment = nlapiGetFieldText('department');

nlapiSetCurrentLineItemText('item', 'department', itemDepartment);



回答2:

The id of the department column field is also department, same as the header field. Therefore, the second line of you snippet should be:

nlapiSetCurrentLineItemValue('item','department',itemDepartment);

EDIT As per the comment below, please find below the full code snippet to populate lines department from the customer on before submit:

    function onBeforeSubmit(type) {
           if (type == 'create' || type == 'edit') {
               var customerId = nlapiGetFieldValue('entity');
                var itemDepartment = nlapiLookupField('customer',customerId, 'custentity_department');
                var itemCount = nlapiGetLineItemCount('item');
                for (var i = 1; i <= itemCount; i++) {
                    nlapiSetLineItemValue('item', 'department', i, itemDepartment);

                }
            }

      }

Also, as a side note, you don't have to load the whole record in order to get a field value. You should use nlapiLookupField instead. It's much faster, safer and less api usage.