SuiteScript Auto Populate Department Line Item Fields

天大地大妈咪最大 提交于 2019-12-24 20:24:26

问题


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.



来源:https://stackoverflow.com/questions/47465539/suitescript-auto-populate-department-line-item-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!