Reputation: 11
I have a suitescript code as below, so how to run it on console to show results.. do have cli need for run?
require(['N'], function(N) {
for(var n in N){window[n] = N[n];};
try{
var s=search.load({id:"572",type:"transaction"});
console.log(s.toJSON());
console.log(s.runPaged().count);
s.run().each(function(r){
console.log(r.toJSON());
return true;
});
} catch(e){console.error(e.message);}})
Upvotes: 1
Views: 2331
Reputation: 609
You can run these scripts by saving them as snippets too which is what I prefer. Generally I write out the following make changes as need a run it within the snippets menu while on a page that is scriptable (like a transaction or a customer).
require(["N/search], function(search) {
var s = search.load({id:"572", type:"transaction"});
// code goes here
})
Upvotes: 0
Reputation: 71
First, make sure you are in a page that is editable and is in edit mode. A good example is to go to a customer record, edit it, and then open the console. This is necessary because not all of the modules are accessible unless there is server-side suitescript running.
Then, you will need to load the modules you need. search is a prime example of this:
let search = require('N/search');
From there, you can run your code in the console - just remove the require clause.
See this for more details: https://stoic.software/effective-suitescript/8-ss2-console/
Upvotes: 5