Search code examples
netsuitereturn-typesuitescript2.0entry-point

SuiteScript 2.0 RESTlet - Error: entry point scripts must implement one script type function. Confused on return statement


I'm having a really hard time understanding the return statement after reading through the NetSuite documentation. I am getting the following error: "entry point scripts must implement one script type function."

Here is the sample HelloWorld code to point out what I'm not understanding:

    return {    //4. return statement 
        pageInit: helloWorld
    };

What exactly is pageInit in the above code? I know it's defining the entry point function, but as what? It seems to be the action that would cause this script to run, but I have no idea what it is called. I've also seen onRequest, onLoad and a few others, but I'm not sure what they are so I can find a list of them.

EDIT: These are ENTRY POINT EVENTS.

From my understanding, you specify this value (pageInit above), then set it to the Entry Point function that corresponds.

Here is my code causing the error:

/**
 * @NApiVersion 2.0
 * @NScriptType Restlet
 * @NModuleScope Public
 */

require(['N/search'], //1. Define Function
    function(search) {  //2. Call Back Function
        function search(datain) {   //3. Entry Point Function
            var searchId = datain.savedsearchid;

            var mySearch = search.load(searchId);

            var resultsSet = mySearch.run();

            var searchid = 0;
            do {
                var resultslice = resultset.getResults( searchid, searchid+1000 );
                for (var rs in resultslice) {
                    results.push( resultslice[rs] );
                    searchid++;
                }
            } while (resultslice.length >= 1000);
        }   

        return {
            onRequest : search
        };
    }
);

Thanks for taking a look.


Solution

  • RESTlets have four different functions (entry points) that you can use: get, put, post, delete. If you used the Eclipse default script generator, to build your initial file, the return would look like this.

    return{
      'get':doGet,
      put:doPut,
      post:doPost,
      'delete':doDelete
    };
    

    The functions can be named anything your want (for the most part), but you have at least one of the entry points (get, put, post, delete).

    SuiteScript 2.0 RESTlet Script Type