I'm trying to create a script file on NetSuite using SuiteScript 2.0 to update the External Id of the classification records. For some reason, NetSuite updates all fields but externalId.
I want to create this script to update the externalIds because mostly of our CSV templates uses the externalIds to look for master data such as accounts and classes. The point is, NetSuite doesn't show the externalIds on the forms and all the records created via UI, has no information in this field. So the idea here is to schedule a script to fill this field automatically based on some other fields.
Here is my code
/**
* @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
};
});