0
votes

I have a JavaScript library file that I use throughout my scripts when creating SuiteScripts for NetSuite. I'm trying to get myself all prepped on 2.0 and start pushing new projects to it and get away from SuiteScript 1.0. So, I transcribed my library file into 2.0. However, whenever I create a new script and have my library referenced, I always get the following message:

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

But, if I remove the reference from the script, it lets me load it up and create the script record. Then I can put the reference back and upload the revised script file without issue. I can't for the life of me understand why this happens. If it matters, here is the JSDoc header in the file:

/** 
 * my.library.v2.js
 * @NApiVersion 2.x
 * @NModuleScope Public 
 */

A script would also start off like this after its own JSDoc header:

define(['N/error', 'N/record', 'N/runtime', 'N/search', './my.library.v2'],
function(error, record, runtime, search, myLib) {
    function doStuff(context) { /* do a bunch of stuff */ }
    return { pageInit : doStuff };
});

Along the same issue, I also have trouble with running some scripts. Everything works perfectly when applying this module to client scripts once I get beyond the previously mentioned issue. However, I cannot successfully get a server-side script to initiate with the library. I constantly get this error:

com.netsuite.suitescript.exception.NLServerSideScriptException: TypeError: Cannot call method "split" of undefined

What's throwing me off is that the library has no call of String.split() inside of it. And I have no way to log where the error may be originating from, as it is occurring when loading the module into the server script. And I know that's what's happening because this occurs regardless of the operation type and the scripts I create always have a condition to check for specific operation types before getting into the nitty gritty. For example, if I have it checking for a "print" operation, but the record is opened to "edit". I even have the entire function wrapped inside of a try/catch block.

I haven't had much luck in tracing the cause of these issues down, so I'm hoping that both isues stem from the same cause.

2

2 Answers

0
votes

If you could post/provide your custom-module it would have helped alot to narrow down the issue, but as far as I can tell, you are including some module which is not available on the server-side scripts like N/currentRecord. This module is only available on client-scripts and will not let you load/create server-side scripts as you mentioned. So, if you remove those modules and try to update/create server-side scripts it should work.

Similarly, there are some modules which can only be used on server-side scripts like N/task module and would return error if you try to load/require them on client side scripts.

0
votes

Ok, so there were errors on my behalf. One of my function definitions was missing "function". Since the functions are being added as properties of an object, I can see why it kept getting overlooked, if you aren't careful enough you eye just glides over the problem. There's also an issue with an array prototype, but I don't think the prototype is necessary for SuiteScript 2.0. It was developed for use with SuiteScript 1.0 due to a lot of handy object functions not yet having been implemented until a later JS version release than what is used for the server side engine in NetSuite.