John
John

Reputation: 69

Netsuite throwing error when trying to upload SuiteScript 2.x file (Fail to evaluate script...)

I'm trying to write a NS script that will loop thru the results of a saved search and update the date expected for a backordered item. Keeping it simple at the moment to see if I can get the results from the search in the script, but I've run into an issue before I can even test run the script in Netsuite. When I try to add the file to the file cabinet (and create a script record), I get the error: "Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"missing } after property list (SS_SCRIPT_FOR_METADATA#33)","stack":[]}"

I'm very new to SuiteScript 2.0 but have had some experience with 1.x. My script is below, but I have no idea what the error means, or how to fix it. I've read in a few posts that I need to use return on my callback function and I don't really understand what that is, but I've tried a couple of 'returns' that didn't work (I really don't need the script to return any data, as I can update the records while in the loop).

/**
 *@NApiVersion 2.x
 *@NScriptType ScheduledScript
 *@NModuleScope Public
 */

require(['N/search', 'N/log'],
    function (search, log) {
        log.debug('Start');
        
        var mySearch = search.load({
            id: 'customsearch_script_update_receive_date'
        });
        
        var myPages = mySearch.runPaged({ pageSize: 1000 });
        for (var i = 0; i < myPages.pageRanges.length; i++) {
            var myPage = myPages.fetch({ index: i});
            myPage.data.forEach(
                function (result) {
                    var internal_id = result.getValue(mySearch.columns[0]);
                    var ns_name = result.getValue(mySearch.columns[1]);
                    var sku = result.getValue(mySearch.columns[2]);
                    var date_expected = result.getValue(mySearch.columns[8]);
                    var quan_expected = result.getValue(mySearch.columns[9]);
                    debugger;
                }
            )   
        }
        
        log.debug('End');
        
        return {
            onRequest : true;
        }
    }
);

Latest script as of 3 Nov 2022 09:55 EST Throwing error: "SuiteScript 2.x entry point scripts must implement one script type function."

/**
 *@NApiVersion 2.x
 *@NScriptType ScheduledScript
 *@NModuleScope Public
 */

require(['N/search', 'N/log'],
    function (search, log) {
    function actualScript(){
        log.debug('Start');
        
        var mySearch = search.load({
            id: 'customsearch_script_update_receive_date'
        });
        
        var myPages = mySearch.runPaged({ pageSize: 1000 });
        for (var i = 0; i < myPages.pageRanges.length; i++) {
            var myPage = myPages.fetch({ index: i});
            myPage.data.forEach(
                function (result) {
                    var internal_id = result.getValue(mySearch.columns[0]);
                    var ns_name = result.getValue(mySearch.columns[1]);
                    var sku = result.getValue(mySearch.columns[2]);
                    var date_expected = result.getValue(mySearch.columns[8]);
                    var quan_expected = result.getValue(mySearch.columns[9]);
                    log.debug({
                        title: 'Log entry',
                        details: internal_id + ' - ' + ns_name + ' - ' + sku + ' - ' + date_expected + ' - ' + quan_expected
                    });
                }
            )   
        }
        
        log.debug('End');
    }
    
    return {
        execute: actualScript
    };
});

Upvotes: 0

Views: 542

Answers (1)

bknights
bknights

Reputation: 15447

You should use a linter to start.

return {
   onRequest : true;
}

is not how to write an object literal. Further a scheduled script function needs to return an execute method. (see the script type docs)

e.g.

/**
 *@NApiVersion 2.x
 *@NScriptType ScheduledScript
 *@NModuleScope Public
 */

define(['N/search', 'N/log'],
    function (search, log) {

        function actualScript(){
            log.debug('Start');
            
            var mySearch = search.load({
                id: 'customsearch_script_update_receive_date'
            });
            
            var myPages = mySearch.runPaged({ pageSize: 1000 });
            for (var i = 0; i < myPages.pageRanges.length; i++) {
                var myPage = myPages.fetch({ index: i});
                myPage.data.forEach(
                    function (result) {
                        var internal_id = result.getValue(mySearch.columns[0]);
                        var ns_name = result.getValue(mySearch.columns[1]);
                        var sku = result.getValue(mySearch.columns[2]);
                        var date_expected = result.getValue(mySearch.columns[8]);
                        var quan_expected = result.getValue(mySearch.columns[9]);
                        debugger;  // does this do anything in a server side script?
                    }
                )   
            }
            
            log.debug('End');
        }
        
        return {
            execute : actualScript
        };
    }
);

Upvotes: 1

Related Questions