Entry Point Script Validation Examples

The following are examples of correct and incorrect SuiteScript scripts. These include:

Includes All Required Elements — Example of a Valid Script

The following script is valid. It includes a define statement, a return statement with an entry point, and an entry point function that corresponds with the entry point. Additionally, the value of the @NScriptType JSDoc tag matches the script type interface used, and the @NApiVersion JSDoc tag is correct.

          /**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */

define(['N/record'], (record) => {
    function myBeforeSubmitFunction(context) {
        if (context.type !== context.UserEventType.CREATE)
            return;
        let customerRecord = context.newRecord;
        customerRecord.setValue({
            fieldId: 'comments', 
            value: 'Please follow up with this customer!'
        });
    }
    return {
        beforeSubmit: myBeforeSubmitFunction
    };
}); 

        

Missing Return Statement — Example of an Invalid Script

The following script is invalid because it does not have a return statement. If you try to upload a script that does not include a return statement, the system returns the error “SuiteScript 2.0 entry point scripts must implement one script type function.” For more information, see SCRIPT_OF_API_VERSION_20_MUST ....

          /**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */

define(['N/record'], (record) => {
    function myBeforeSubmitFunction(context) {
        if (context.type !== context.UserEventType.CREATE)
            return;
        let customerRecord = context.newRecord;
        customerRecord.setValue({
            fieldId: 'comments',
            value: 'Please follow up with this customer!'
        });
    }
}); 

        

Missing Define Statement — Example of an Invalid Script

The following script is invalid because it uses a require statement instead of a define statement. If you try to upload a script that includes a require statement, the system returns the error “SuiteScript 2.0 entry point scripts must implement one script type function.” For more information, see SCRIPT_OF_API_VERSION_20_MUST .... For more information about using the require statement, see require Function.

          /**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */

require(['N/record'], (record) => {
    function myBeforeSubmitFunction(context) {
        if (context.type !== context.UserEventType.CREATE)
            return;
        let customerRecord = context.newRecord;
        customerRecord.setValue({
            fieldId: 'comments',
            value: 'Please follow up with this customer!'
        });
    }
}); 

        

Missing @NScriptType JSDoc Tag — Example of an Invalid Script

The following script is invalid because it does not have an @NScriptType JSDoc tag. You can upload the script file, however, if you try to create a script record for this script, the system returns the error “@NScriptType is required for 2.0 entry point script.” For more information, see MISSING_SCRIPT_TYPE.

          /**
 * @NApiVersion 2.1
 */

define([ 'N/record' ], (record) => {
    function myBeforeSubmitFunction(context) {
        if (context.type !== context.UserEventType.CREATE)
            return;
        let customerRecord = context.newRecord;
        customerRecord.setValue({
            fieldId: 'comments',
            value: 'Please follow up with this customer!'
        });
    }
    return {
        beforeSubmit : myBeforeSubmitFunction
    };
}); 

        

Missing @NApiVersion JSDoc Tag — Example of an Invalid Script

The following script is invalid because it does not have an @NApiVersion JSDoc tag. If you try to upload a script file that does not include the @NApiVersion JSDoc tag, the system returns the error “Failed to validate script file.” For more information, see FAILED_TO_VALIDATE_SCRIPT_FILE.

          /**
 * @NScriptType UserEventScript
 */

define(['N/record'], function(record) {
    function myBeforeSubmitFunction(context) {
        if (context.type !== context.UserEventType.CREATE)
            return;
        let customerRecord = context.newRecord;
        customerRecord.setValue({
            fieldId: 'comments',
            value: 'Please follow up with this customer!'
        });
    }
    return {
        beforeSubmit : myBeforeSubmitFunction
    };
}); 

        

Related Topics

SuiteScript 2.x Entry Point Script Validation
Entry Point Script Validation Guidelines
Entry Point Script Validation Error Reference

General Notices