I am trying to upload a .js file (my suite script) on to NetSuite but am getting the following error.
Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"missing ; before statement (SS_SCRIPT_FOR_METADATA#15)","stack":[]}
The Script in question:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define([ 'N/record' ],function(record) {
function afterSubmit(context) {
// Load the record.
var rec = record.load({
type: record.Type.INVENTORY_ITEM,
id: 4918
});
let pricing_group = rec.getValue({
fieldId: 'pricinggroup'
});
if (part_group == '') return;
let current_desc = rec.getValue({
fieldId: 'salesdescription'
});
rec.setValue({
fieldId: 'salesdescription',
value: pricing_group + ' | ' + current_desc,
ignoreFieldChange: true,
forceSyncSourcing: true
});
// Save the record.
try {
var recId = rec.save();
log.debug({
title: 'Record updated successfully',
details: 'Id: ' + recId
});
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
}
return {
afterSubmit: afterSubmit
};
});
The syntax is correct running it on a syntax validator so I'm not sure where ';' is missing.
You have some syntax errors in your script (which are errors in SuiteScript 2.0, but not 2.1, namely you are using the let
keyword, which is not valid in SuiteScript 2.0). The error actually is about one of them.
Try this:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define([ 'N/record' ],function(record) {
function afterSubmit(context) {
// Load the record.
var rec = record.load({
type: record.Type.INVENTORY_ITEM,
id: 4918
});
var pricing_group = rec.getValue({
fieldId: 'pricinggroup'
});
if (part_group == '') return;
var current_desc = rec.getValue({
fieldId: 'salesdescription'
});
rec.setValue({
fieldId: 'salesdescription',
value: pricing_group + ' | ' + current_desc,
ignoreFieldChange: true,
forceSyncSourcing: true
});
// Save the record.
try {
var recId = rec.save();
log.debug({
title: 'Record updated successfully',
details: 'Id: ' + recId
});
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
}
return {
afterSubmit: afterSubmit
};
});