How to override Usage Limit exceed with help of Schedule Script or Suitelet?


Supporting script for usage
Supporting Scripts


Hi All,

There are 2 type of Governance Usage Limit:
1. API Level
2. Script Level,
Also we all know we can not increase Governance Usage Limit of Scripts. We can write our scripts within limit. Best example is that a suitelet have 1000 Usage limit , means every time suitelet is called it is allowed to use all API with in 1000 governance usage.

Is there any way we can get rid of Governance Limit?

Answer is No and Yes both. We can not increase native limit but we can use other type of scripts as a supporting script.However this sometime slow down process or take few seconds to execute depending upon which supporting script you use.

Easiest and Simplest example here to understand is that if you want to update 5 record then load and submit will take 30 for 1 record and 150 for 3. and this 150 becomes worst case if you only have less 150 in hand, so if you make a suitelet and call that suitelet it will cost only 10(using nlapiRequestURL).so this way you are saving 140 usage.

Client Script as a Supporting script for Suitelet and Portlet:

Suitelet Have 1000 Usage limit which most of the time is sufficient to process data, how ever when you work on historic data or when data is huge then it creates problem in processing.
Point to note here that Client script always slow down the process but if you want to do some validation you can do in client script and this will allow you to find errors before submit only.
If your code is using searches or loading to validate data coming from Suitelet then it is best to validate using client script.
If any API is only supported in server side then take help of another suitelet , pass parameter , get validation result in json or simple string and then show message/alert on Suitelet accordingly.

Use form.setScript(); for this purpose.
Note*:- CS slow down process so use CS wisely. and Never Update record on CS.

Schedule Script as a supporting script for User Event:

As we all know only 1000 usage are allowed where as in Schedule Script limit is of 5000 Usage. So if we can move our complex part to process and update in schedule script, it will be added advantage for User Event Script.
In Schedule Script make Script Parameter (if you want to pass value in script) and then pass value and call schedule script inside user event . 
Code:
var data = [];
data['custscript_param1'] = value1;
nlapiScheduleScript('Schedule Script Id Here', 'schedule script id here', data);
Note*-: Please scehdule script should be in not schedule status, also execution depends on deployment queue, so if queue is empty it might work in 2-4 send, else might take few minutes also. So assign high priority to these scripts.

Suitelet as Supporting Script for User Event:

Though we can use Suitelet call inside user event but this is not best way to do for user event. Schedule script is best supporting script and it never put extra pressure on user event. 
you can use nlapiRequestURL and it will cost you only 10 usage, you can save all usage if you move your code to suitelet but it is not advisable as it will slow down the process.only benefit is that it will make sure your logic work that moment only. User will not see any delay and no need to refresh and check.

Suitelet As Supporting Script for Restlet:

This is most useful case after schedule-user event combo. When you call restlet and you are not able to process all in restlet then user user event, as restlet require some response thats why you can not use schedule script or another script. Write you logic in Suitelet and send required response to Restlet, now if you need suitelet's response to do something further in Restlet , do that and return final response to calling Application, if suitelet response is final response then return same response in Restlet response too.

 //======this is restlet =============

function callSuitelet(datain)
{
    var myid= datain.myid;
    try
    {
        var suite = nlapiRequestURL('suiteletUrlHere');
        var message = '';
        if(suite)
        {
            message = suite.getBody();
        }
        else
        {
            message = 'no message';
        }
        var output = '{"myid":"' + myid+ '","message":"+message+"}';     
        return JSON.parse(output);
    }
    catch(e)
    {
        var output = '{"myid":"' + myid+ '","message":"error: +e+"}';     
        return JSON.parse(output);
    }
}


//----------------This is Suitelet-------------------
function suiteletURL(request, response)
{
    try
    {
        var message2 = '';
        //your logic here
        response.write(message2);
    }
    catch(e)
    {
            response.write('error'+e);
    }
}
Please let me know if you have any doubt. 

Thanks
Abhi

Comments

Post a Comment

Thanks for you message, please join us on Facebook and Linkedin