SuiteScript自动填充部门行项目字段 [英] SuiteScript Auto Populate Department Line Item Fields
问题描述
我正在尝试按照部门交易正文字段填充部门行项目字段,请协助检查我的代码是否正确.
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);
它一直在声明department_display
不是内部ID.
It keeps stating that department_display
is not an internal ID.
请告知.
谢谢.
推荐答案
部门列字段的ID也是部门,与标头字段相同. 因此,您的摘要的第二行应为:
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);
}
}
}
此外,作为旁注,您不必加载整个记录即可获取字段值.您应该改为使用nlapiLookupField.它更快,更安全并且使用的API更少.
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.
这篇关于SuiteScript自动填充部门行项目字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!