Resolve Error “Custom Module Call Undefined” in SuiteScript 2.0

In SuiteScript 2.0, make sure to beautify or format your code to avoid undefined calls from the originating script.

define(['N/error', 'N/file', 'N/format', 'N/https', 'N/record', 'N/render', 'N/runtime', 'N/search', 'N/xml'],
function(error, file, format, https, record, render, runtime, search, xml)
{‌
    function execute(scriptContext)
	{‌
    	var cmsearch = search.load(
		{‌
    		id: 'customsearch42'
    	});
    	log.debug(
		{‌
						title: "Start"
    	});


    	var resultsSet = cmsearch.run();
        var results = resultsSet.getRange(0, 999);
    	for (var i = 0; results != null && i < results.length; i++)
		{‌
    		var tranId = results[i].getValue(
			{‌
                name: "tranid"
            });
    		var total = results[i].getValue(
			{‌
                name: "amount"
            });
    		log.debug("total", tranId);
    		log.debug("total", total);
    	}
    }


    return {‌
        execute: execute
    };


});

Sample of a well-formed script: 

define(['N/error', 'N/file', 'N/format', 'N/https', 'N/record', 'N/render', 'N/runtime', 'N/search', 'N/xml'],
    function(error, file, format, https, record, render, runtime, search, xml) {‌
        function execute(scriptContext) {‌
            var cmsearch = search.load({‌
                id: 'customsearch42'
            });
            log.debug({‌
                title: "Start"
            });


            var resultsSet = cmsearch.run();
            var results = resultsSet.getRange(0, 999);
            for (var i = 0; results != null && i < results.length; i++) {‌
                var tranId = results[i].getValue({‌
                    name: "tranid"
                });
                var total = results[i].getValue({‌
                    name: "amount"
                });
                log.debug("total", tranId);
                log.debug("total", total);
            }
        }


        return {‌
            execute: execute
        };


    });

Leave a comment

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