eklon
eklon

Reputation: 127

"SuiteScript 2.0 entry point scripts must implement one script type function" Error

I'm trying to upload this code to NetSuite

/**
 * @NApiVersion 2.0
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define(['N/ui/dialog'],

function(dialog){

   /**
     * Validation function to be executed when sublist line is committed.
     *
     * @param {Object} context
     * @param {Record} context.currentRecord - Current form record
     * @param {string} context.sublistId - Sublist name
     *
     * @returns {boolean} Return true if sublist line is valid
     *
     * @since 2015.2
     */





   function validadeRate(context){

    try{

        var currentRecord = context.currentRecord
        var sublistName = context.sublistId

        if(sublistname ==='expense'){

            var categ = CurrentRecord.getCurrentSublistValue({
                sublistId: sublistName,
                fieldId: 'category'

            })
            if ((categ = 259) && (rate != 0.819)){
                var currIndex = currentRecord.getCurrentSublistIndex({
                    sublistId: sublistName
                })
             currIndex +=1

             var options = {
                title : 'Rate Incorreto!',
                message:'Por favor, verifique o valor informado no campo Rate na linha ' + currIndex + '.',                            
                }
                dialog.alert(options).then(function (result) { }).catch(function(result){})
                    
                return false
             }
            }
            return true
    }
    catch(ex){
        log.error('validateLine: ', ex.message)
    }

   }


    return {

        validadeRate : validadeRate

    }
});

But I'm getting this error when I'm trying to upload to file to Netsuite:

Notice

SuiteScript 2.0 entry point scripts must implement one script type function.*

This is part of a function that will validade the rate for one expense category.

How can I solve this?

thanks in advance!

Upvotes: 0

Views: 8533

Answers (3)

Change return function as below. and test once.


return { validateLine : validadeRate }

Upvotes: 0

Krypton
Krypton

Reputation: 5286

This is NetSuite's 'Entry Point Script Validation' saying that the script is invalid because it doesn't include one of the predefined entry point (event) functions. These functions are:

fieldChanged

lineInit

pageInit

postSourcing

saveRecord

sublistChanged

validateDelete

validateField

validateInsert

validateLine

You can work around this validation and upload the script by adding one of those entry points, even if it does nothing. For example, inside your function (dialog) function you can add a pageInit() function:

function pageInit(scriptContext) {}

and change your return block to:

return {

    validadeRate : validadeRate,
    pageInit: pageInit

}

Now it has a valid entry point and the validation should pass.

However, there may be an even easier way. It appears (going by the JSDoc block), that your validadeRate function is supposed to be triggered each time a sublist line is added. This is exactly what the validateLine entry point is for. So you could just change the key in your return block to "validateLine"

return {
    validateLine: validadeRate
}

and NetSuite would know to call validadeRate each time a line is added.

Upvotes: 3

erictgrubaugh
erictgrubaugh

Reputation: 8902

You have specified this as a Client Script module, but have not assigned a handler to any of the Client Script entry points. Read the Help document SuiteScript 2.0 Client Script Entry Points and API, and implement any one of the entry points in your module.

Upvotes: 0

Related Questions