SuiteScript Auto Populate Department Line Item Fie

2019-08-18 04:24发布

Code Portion Click Hereenter image description 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.

2条回答
可以哭但决不认输i
2楼-- · 2019-08-18 04:56

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);

查看更多
爷的心禁止访问
3楼-- · 2019-08-18 04:59

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.

查看更多
登录 后发表回答