Reputation: 2983
I really hate the way netsuite suite script 2.0 handles date formatting. So, I would like to use Moment.js for parsing dates that I get back from a web service call. How do I get this to work inside a suite script 2.0?
As erictgrubaugh stated, I needed to add the moment.js library to the NetSuite file cabinet and then in the debugger use the library. Also note that my script is in File Cabinet -> SuiteScripts -> Libraries
But even so, I was having problems with the syntax. Because when I use the debugger it now doesn't throw any errors, but I can't step through any of the code and a log statement doesn't print anything.
/** * @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
define ([
'N/log',
'../Libraries/moment',
],
function(log, moment) {
var a = moment('2016-01-01');
var b = a.clone().add(1, 'week');
log.debug(b);
});
Upvotes: 1
Views: 9181
Reputation: 33
I can , in debugger:
require(["SuiteScripts/moment"], function (moment) {
var __d= moment().format();
var x =0; //breakpoint
});
this works
Upvotes: 0
Reputation: 8847
In general, the external library simply needs to be an AMD-formatted module, and you can include it directly in your code. If the library you want to use isn't AMD-compatible, there is extra work to do.
moment
is AMD-compatible, so all you need to do is put the moment
source file in your File Cabinet somewhere, then include it in your dependencies by its path.
require(["path/to/moment"], function (moment) {
// use moment as usual
});
Here's a working example where I have moment.min.js
in a sibling lib
directory: https://gitlab.com/stoicsoftware/netsuite-sku-analytics/blob/master/FileCabinet/SuiteScripts/sku-analytics/total-monthly-by-sku/sa-TotalMonthlyBySku.js
Upvotes: 6
Reputation: 1598
You said:
Because when I use the debugger it now doesn't throw any errors, but I can't step through any of the code and a log statement doesn't print anything.
But from the documentation:
Note If you need to ad-hoc debug your code in the NetSuite Debugger, you must use a
require()
function. The NetSuite Debugger cannot step though adefine()
function.
Upvotes: 4