<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Avi on Medium]]></title>
        <description><![CDATA[Stories by Avi on Medium]]></description>
        <link>https://medium.com/@avivashisth?source=rss-a4ab78a271ee------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*z1En9-Oxvvjb0Cu8.jpg</url>
            <title>Stories by Avi on Medium</title>
            <link>https://medium.com/@avivashisth?source=rss-a4ab78a271ee------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:39:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@avivashisth/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[NetSuite: Optimizing SuiteScript with Progressive Loading]]></title>
            <link>https://avivashisth.medium.com/netsuite-optimizing-suitescript-with-progressive-loading-35332dcc6502?source=rss-a4ab78a271ee------2</link>
            <guid isPermaLink="false">https://medium.com/p/35332dcc6502</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[suitescript]]></category>
            <category><![CDATA[netsuite]]></category>
            <dc:creator><![CDATA[Avi]]></dc:creator>
            <pubDate>Fri, 27 Dec 2019 20:43:51 GMT</pubDate>
            <atom:updated>2021-03-23T05:47:41.160Z</atom:updated>
            <content:encoded><![CDATA[<h3>Progressive Loading in NetSuite</h3><p>Lately we were facing performance issues with NS scripts, and it wasn’t that we were making un-wanted search/record-loads. As our bundle started to grow overtime it started casuing performance issues since we were always adding new features. Thats when we decided to use NetSuite’s progressive loading on our server side scripts(like RESTlet, Suitelet, User-Events etc) and it offered some performance benefits.</p><p>So, here is why you too need to use Progressive loading in your scripts and modules.</p><p>Suppose, you have a user-event script, where all/multiple entry functions are implemented and you have requested some standard NetSuite modules along with some custom modules with the define object like below</p><pre>define([<br>  &#39;N/record&#39;, &#39;N/search&#39;,<br>  &#39;./custom_customer_module&#39;, &#39;./custom_sales_order_module&#39;,<br>  &#39;./custom_module&#39;<br>], function (record, search, CustomerModule, SalesOrderModule,<br>  SomeOtherModule<br>) {</pre><pre>  /**<br>   *<br>   * @param {Object} context<br>   * @prop  {String} context.type<br>   * @prop  {Object} context.newRecord<br>   * @prop  {Object} context.UserEventType<br>   */<br>  function beforeLoad(context) {<br>    var type = context.type;</pre><pre>    if (type !== context.UserEventType.CREATE) {<br>      return;<br>    }</pre><pre>    var seachResult = search.create({});</pre><pre>    // update some fields/data in newRecord<br>    <br>  }</pre><pre>  <br>  /**<br>   *<br>   * @param {Object} context<br>   * @prop  {Object} context.newRecord<br>   */<br>  function beforeSubmit(context) {<br>    var newRecord = context.newRecord;</pre><pre>    var recordType = newRecord.type;</pre><pre>    if (recordType === &#39;salesorder&#39;) {<br>       return SalesOrderModule.doSomething({ <br>         salesOrder: newRecord <br>       });<br>     } else if (recordType === &#39;customer&#39;) {<br>       return CustomerModule.doSomething(context);<br>     } else if (recodType === &#39;purchaseorder&#39;) {<br>       var someSalesOrder = record.load({ <br>         type: &#39;salesorder&#39;, <br>         id: SOME_SALES_ORDER,<br>         isDynamic: true<br>       });<br>       return SalesOrderModule.doSomething({ <br>         salesOrder: someSalesOrder <br>       });<br>     }<br>   }<br></pre><pre>   /**<br>    *<br>    * @param {Object} context<br>    * @prop  {Object} context.newRecord<br>    */<br>   function afterSubmit(context) {<br>     var newRecord = context.newRecord;</pre><pre>     return SomeOtherModule.processSomething(context);<br>   }</pre><pre>  return {<br>    beforeLoad: beforeLoad,<br>    beforeSubmit: beforeSubmit,<br>    afterSubmit: afterSubmit<br>  };<br>});</pre><p>So, all these modules are fetched and loaded before the callback in script is executed. But you won’t be using all the specified module in some cases. So why require them at load time and not when you actually need them?</p><p>Turns out, you can require these modules when you actually need them. This will reduce your script-load time and some scripts which are not used, will not be loaded provided you don’t require them ;).</p><p>To require/load scripts at load time, you need to use <em>require</em> function provided by NetSuite.</p><p>Now you can either directly use it in your script as below</p><pre>define([], function () { <br>  function doSomethingInteresting() {<br>    require([SOME_MODULE], function (someModule) {<br>      // do something</pre><pre>    })<br>  }<br>}</pre><p>or load require module by specifying it in define arguments as follows</p><pre>define([&#39;require&#39;], function (require) {}); </pre><p>But there is major difference between the two. As per NetSuite, use the first example</p><blockquote>To import modules via absolute path.</blockquote><p>i.e your module path should start from <em>Suite Scripts</em> or <em>Suite Bundle </em>like</p><p><em>Suite Scripts/some_dir/custom_module</em></p><p>The second approach provides a context i.e you can use relative paths to require custom modules like</p><p><em>./some_dir/custom_module</em></p><p>If you use the first approach, you have to use absolute path. But if your script is a part of a bundle and you have multiple clients/NS-Accounts using that bundle, you will need to make the scripts public i.e set its module-scope to Public so that it can be loaded progressively. That means if you are developing a feature in SandBox and it needs to be migrated to Production of the same account, you can use it since this approach. But if you are developing scripts in some test/development account, making your script public won’t be a valid option for you.</p><p>So in that case you can use the second approach and first load require module in define-object, this provides you with the context of the entry script and then you can progressively load your custom-modules when needed.</p><p>You can use progressive loading to load standard NetSuite modules as well.</p><p><strong>Note: </strong>In client-scripts, require-function works asynchronously and so you should pass callback method to fetch modules.</p><p>Here is the sample script that you can use to progressively load modules in your scripts.</p><pre>define([‘require’], function (require) {</pre><pre>  /**<br>   * @desc  `cb` is required for client-scripts, on server side require works synchronously.<br>   *<br>   * @param {String} path  module path like N/record or ./some_custom_module<br>   * @param {Callback} cb callback method used in client scripts<br>   */<br>  function getModule(path, cb) {<br>    var mod;<br>    <br>    require([path], function (m) { <br>      mod = m;<br>      <br>      return cb <br>        ? cb(mod) <br>        : mod;<br>    });</pre><pre>    return mod;<br>  }</pre><pre>  return {<br>    getModule: getModule<br>  };<br>});</pre><p>For further reading check <a href="https://tstdrv1395241.app.netsuite.com/app/help/helpcenter.nl?fid=section_4704230948.html">NetSuite’s</a> doc out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35332dcc6502" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trigger Workflow from script and process them asynchronously]]></title>
            <link>https://avivashisth.medium.com/trigger-workflow-from-script-and-process-them-asynchronously-3e93e454718a?source=rss-a4ab78a271ee------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e93e454718a</guid>
            <category><![CDATA[workflow]]></category>
            <category><![CDATA[suiteflow]]></category>
            <category><![CDATA[suitescript]]></category>
            <category><![CDATA[netsuite]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Avi]]></dc:creator>
            <pubDate>Sat, 23 Nov 2019 05:31:58 GMT</pubDate>
            <atom:updated>2020-05-08T07:29:24.596Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qnexr-p-Xn4Wu6bq" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=medium&amp;utm_medium=referral">Fotis Fotopoulos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Workflow: Async Processing in Near Real-Time</h3><p>So I have been working with Workflows (or SuiteFlow) for some time and wanted to get a few things documented so that it can be useful to others and me too after sometime:).</p><ol><li>You can trigger workflows manually using the following 2 modules,<br><a href="https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4345787858.html">N/task</a> and <a href="https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4341725558.html">N/workflow</a> where, task module creates a queue entry for specified workflow and is processed asynchronously while in workflow module, it is processed in real time.</li><li>If you have used task module to pass values to scripts paramters, you can use the same to pass values to workflow, provided you have created parameters in your workflow :). But you can’t read them(in custom workflow action) as you would in a Map/Reduce or Scheduled Script.<br>So, to read values from workflow/state parameter , you have to first create a script parameter in your custom workflow and pass it default value in the action from workflow state and then read value from workflow action script param.</li><li>If your workflow has multiple states/action and you want to skip a few of them, you can use <em>workflow.trigger. <br>e.g. Y</em>ou have a workflow with 2 states, where State#1 adds a button on SalesOrder and on its click event you want it to transition to State#2, where you have your logic to perform some other operation. In this case you don’t want to be stuck at state#1 (where you just add button adn wawit for user to click the button, instead you want to trigger button click) while triggering workflow from script, so in that case you can use workflow.trigger and pass it the ActionId which is the action which adds button on SalesOrder, like in State#1 in our case and this will work as if user has clicked button from UI and it will be transitioned to our State#2 of the workflow.</li></ol><p>We had a scenario where we wanted to update customer record once a custom record was updated, now since user was on a custom record and this could be done in background asynchronously without user intervention, so instead of writing the whole script to update customer record in user-event script, we triggered a workflow using task module which would in turn update the customer record. To trigger workflow using task module, you can use the following,</p><pre>require([&#39;N/task&#39;],<br>  function (task) {<br>    var workflow = {};</pre><pre>     /**<br>      *<br>      * @param {Object} args<br>      * @prop  {Object} args.params<br>      * @prop  {String} args.recordId<br>      * @prop  {String} args.recordType<br>      * @prop  {String} args.workflowId<br>      */<br>     function trigger(args) {<br>       var taskId = task.create(util.extend({<br>         taskType: task.TaskType.WORKFLOW_TRIGGER,<br>       }, args))<br>         .submit();</pre><pre>      log.debug({<br>        title: &#39;Workflow Task Details&#39;,<br>        details: {<br>          taskId: taskId, <br>          taskStatus: workflow.getStatus({ taskId: taskId }) }<br>        }<br>      });</pre><pre>      return taskId;<br>    }<br></pre><pre>    /**<br>     *<br>     * @param {String} taskId<br>     *<br>     * @return {String} TASK_STATUS<br>     */<br>    function getStatus(taskId) {<br>      return task.checkStatus({ taskId: taskId }).status;<br>    }</pre><pre>    workflow.trigger = trigger;<br>    workflow.getStatus = getStatus;</pre><pre>    return workflow;<br>  }<br>);</pre><p>Now, consider a scenario where you want to update a record in user-event(suitelet, map/reduce, restlet etc), for which you already have a logic in a Workflow and you want this values before you can move any further, you may not want to copy the same script again to avoid code redundancy. In that case you can use workflow module to fire a workflow in synchronous mode and once its completed, your current record will be updated or will refelect the latest values after the workflow has executed.</p><p>If you can want to trigger workflow from a specific state like your workflow first adds a button and on button click you want to perform some operation, you can use workflow module as below and pass stateId</p><pre>require([&#39;N/workflow&#39;],<br>  function (workflow) {</pre><pre>    /**<br>     * @desc  if stateId/actionId is passed,<br>     *     calls `workflow.trigger` to take workflow at specific<br>     *     state/action specified<br>     *<br>     * @param {Object} args<br>     * @prop  {String} args.stateId<br>     * @prop  {String} args.actionId<br>     * @prop  {String} args.recordId<br>     * @prop  {String} args.workflowId<br>     * @prop  {String} args.recordType<br>     * @prop  {Object} args.defaultValues<br>     */<br>    function trigger(args) {<br>      return (args.stateId || args.actionId)<br>        ? workflow.trigger(args)<br>        : workflow.initiate(args);<br>    }</pre><pre>    return {<br>      trigger: trigger<br>    };<br>  }<br>);</pre><p>If you want to directly go to a specific state, you can pass it the stateId and if you want to perform an specific action within a state, you can pass the actionId e.g if you pass the actionId of a button, NetSuite will process it as if the button was clicked by some user.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e93e454718a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NetSuite’s: Script Execution Usage Limit Exceeded]]></title>
            <link>https://avivashisth.medium.com/netsuites-script-execution-usage-limit-exceeded-e748b573655b?source=rss-a4ab78a271ee------2</link>
            <guid isPermaLink="false">https://medium.com/p/e748b573655b</guid>
            <category><![CDATA[netsuite]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[suitescript]]></category>
            <dc:creator><![CDATA[Avi]]></dc:creator>
            <pubDate>Thu, 05 Sep 2019 03:08:33 GMT</pubDate>
            <atom:updated>2021-01-17T05:26:20.511Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kOmCiwX6dFXzx9Fm" /><figcaption>Photo by <a href="https://unsplash.com/@ngeshlew">Lewis Ngugi</a> on <a href="https://unsplash.com/s/photos/programming">Unsplash</a></figcaption></figure><p>At some point, you must have heard or encountered NetSuite’s <strong><em>Script Execution Usage Limit Exceeded</em></strong> message and it is kind of irritating when you don’t know the limit allocated to a certain script.</p><p>These limits are used by NetSuite to govern every script, so that custom scripts does not affect user experience.</p><p>For every script types supported, NetSuite has an fixed/pre-defined execution points allotted. So we have to stay within those limits while scripting.</p><p>Here is the list of some scripts supported by NetSuite and its execution limit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ff043cfc001080ea9e406d8326ab2f3/href">https://medium.com/media/0ff043cfc001080ea9e406d8326ab2f3/href</a></iframe><p><strong>Note:</strong> All of the scripts have entry points predefined for it(SuiteScript 2.x). If a script has multiple entry points(like <em>user-event</em> etc), all of them have the same execution limit i.e total limit allocated to the script.</p><p>To fetch remaining execution limits, you can use <em>runtime</em> module provided by NetSuite and is available on both server and client side scripts.</p><pre>require([‘N/runtime’], function (runtime) {<br>  var remainingUsage = runtime<br>    .getCurrentScript()<br>    .getRemainingUsage();<br>});</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e748b573655b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>