How to fix ‘Syntax error: missing ; before statement’ for suitescript documents version 2.0 and below


Suitescripts written in version 2.0 or below shows this error ‘Syntax error: missing ; before statement’ even when there is ‘;’ present after every single line of code.


For example check this client script sample code in suitescript v2.0.(This is a sample code and not used for any specific purpose)

/**
*@NApiVersion 2.0
*@NScriptType ClientScript
*/
define(['N/ui/dialog','N/search'],
function(dialog,search) {
function pageInitfun(Scriptcontext)
{
let cRecord = Scriptcontext.currentRecord;
let mode = Scriptcontext.mode;
let options = {
title: 'Hello!',
message: 'pageInit Triggered!'
};
try {
dialog.alert(options);
log.debug ({
title: 'Success',
details: 'cRecord: '+cRecord+' mode: '+mode
});
}
catch (e) {
log.error ({
title: e.name,
details: e.message
});
}
}
return {
pageInit: pageInitfun
};
});


Here at first glance there is no error and every line of code has a semicolon ‘;’.We can conclude that error is not caused by the missing of ‘;’.
Usually this error is caused by usage of invalid type keywords that are not supported by suitescript version. For example the type keywords ‘let’ is not supported in suitescript version 2.0. To fix the error we just have to replace the ‘let’ keyword with ‘var’.
Check with the suitescript version documentation for supported data types in case of such errors.

Version 1.0 https://docs.oracle.com/pdf/E87856_03.pdf

Version 2.0 https://docs.oracle.com/pdf/E87857_07.pdf

Leave a comment

Your email address will not be published. Required fields are marked *