我不确定如何排除故障或此错误在 NetSuites SuiteScript 中意味着什么。我在日记条目上点击保存后得到的是:
“TypeError:无法读取未定义的属性‘getLineCount’[at Object.beforeSubmit (/SuiteScripts/Set Line Employee ADP ID.js:15:30)]”
我认为错误出在第 15 行的 getLineCount() 函数上。
功能场景:我正在编写一个脚本,以从在日记条目行的本机实体字段中选择的客户记录上的字段填充日记条目行上的自定义列字段。
上下文:我的脚本在提交创建或更新日记条目之前触发
这是我的脚本:
define (['N/record','N/runtime','N/search','N/log'],(rec,runtime,search,log)=> {
// Logic Of the before submit actions of the script:
function beforeSubmit(context){
//Find how many lines are in this JE
let jeLineNums = context.rec.getLineCount({
sublistId:'line'
});
//log the JE line numbers as a test
log.debug({
title: 'JE lines',
details: jeLineNums
});
// Loop through every line in the Journal Entry
for (let i = 0; i < jeLineNums; i++){
// Find the customer record ID of the customer on the line and store it
let customerid = context.rec.getSublistValue({
sublistId: 'line',
fieldId: 'entity_display',
line: i
});
// Then create a SS with the customer id as a criteria
let customerSearch = search.create({
type: "customer",
filters:
[
["entityid","is",customerid]
],
columns:
[
search.createColumn({
name: "custentity2",
label: "ADP ID"}),
],
});
// Run that ss and Store the ADP ID result into a vairable
function RunSearch(searchVar) {
return searchVar.run()
};
};
RunSearch(customerSearch).each(function(result){
var adpID = result.getValue({
name:'custentity2',
});
return false;
});
//log the JE line numbers as a test
log.debug({
title: 'CustomerADP ID',
details: adpId
});
// Set the Line Employee ADP ID field value to the ADP ID vairable stored
context.rec.setSublistValue({
sublistId: "line",
fieldId: "custcol_mhi_line_adp_id",
line: i,
value: adpId,
});
//End of the loop
};
return {
beforeSubmit: beforeSubmit,
};
});`
对于 SS2.1,您可以执行以下操作:
let { newRecord } = context;
//Find how many lines are in this JE
let jeLineNums = newRecord.getLineCount({
sublistId:'line'
});
或者,对于 SS2.0:
//Find how many lines are in this JE
var jeLineNums = context.newRecord.getLineCount({
sublistId:'line'
});
“TypeError:无法读取未定义的属性‘getLineCount’[at Object.beforeSubmit (/SuiteScripts/Set Line 员工 ADP ID.js:15:30)]"
您收到上述错误的原因是因为您试图从
context
中读取未定义的属性。 context
对象没有 rec
属性。在此处查看更多详细信息:beforeSubmit(上下文)