我正在尝试使用 SuiteScript 2.0 在 NetSuite 上创建一个脚本文件来更新分类记录的外部 ID。出于某种原因,NetSuite 更新了除 externalId 之外的所有字段。
我想创建这个脚本来更新 externalIds,因为我们的大多数 CSV 模板都使用 externalIds 来查找主数据,例如帐户和类。关键是,NetSuite 不会在表单上显示 externalIds,所有通过 UI 创建的记录在该字段中都没有信息。所以这里的想法是安排一个脚本根据其他一些字段自动填充这个字段。
这是我的代码
/**
* @NApiVersion 2.0
* @NScriptType ScheduledScript
*/
define(['N/runtime','N/log','N/record','N/search'], function(runtime,log,record,search) {
var qtyProjects=0;
function execute(context) {
try
{
log.debug('Script Started');
/********** Update Project (Classes) External ID ***********/
var classificationSearchObj = search.create({
type: "classification",
filters:
[
["externalid","is","@NONE@"]
],
columns:
[
search.createColumn({name: "name",label: "Name"}),
search.createColumn({name: "custrecord_proj_full_name",label: "FullName"}),
search.createColumn({name: "custrecord_proj_manager",label: "ProjectManager"}),
search.createColumn({name: "externalid",label: "Externalid"})
]
});
var prj_srch = classificationSearchObj.run().each(processProject);
log.debug('Quantity of projects: ',qtyProjects);
log.debug('Script Finished');
}
catch(e)
{
log.debug('Error',e.message);
}
}
function processProject(result) {
var number = result.getValue({name: "name"});
var fullName = result.getValue({name: "custrecord_proj_full_name"});
var externalid = result.getValue({name: "externalid"});
qtyProjects++;
log.debug('Update Number|Name|ExternalId: ',number + " | " + fullName + " | " + externalid);
record.submitFields({
"type":'classification',
"id": result.id,
"values": {
"externalId": externalid,
"custrecord_proj_full_name": "Test Ale 2",
}
});
/*
var project_id = project.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
*/
//return true;
}
return {
execute: execute
};
});
最佳答案
你把 ExtermalId 的 id 拼错了,它没有大写的 'I' 作为 externalid
。这应该工作。
根据经验, native 字段 ID 中没有大写字母
关于netsuite - 套件脚本 2.0 : How can I update the externalID through Script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63963391/