This topic contains 5 replies, has 0 voices, and was last updated by borncorp 7 years, 10 months ago.
-
AuthorPosts
-
January 12, 2017 at 1:08 pm #5627
Vesku1980Hello,
Is there a any change to round this issue?
I have a customer that wants to split work order with quantity of 60 to 60 of work orders with quantity of one.
I made a client script that is executed from custom buttom.
Everything works fine, but after creating 33 new work orders Script execution usage is full and scripts stops.
I’t doesn’t make a rollback, it just stops.
Is there any way to write more effectice script that uses less usage units?
My Script :
function splitwo()
{
var id = nlapiGetRecordId();
var WOrec = nlapiLoadRecord(‘workorder’,id);
var count = WOrec.getFieldValue(‘quantity’);
var newcount = count-1;
if (newcount ==’0′)
{
alert (‘No Work orders to create’)
}
else
{
alert (‘Starting to creaate new work orders’);
var assembly = WOrec.getFieldValue(‘assemblyitem’);
var units = WOrec.getFieldValue(‘units’);
var trandate = WOrec.getFieldValue(‘trandate’);
var orderstatus = WOrec.getFieldValue(‘orderstatus’);
var firmed = WOrec.getFieldValue(‘firmed’);
var startdate = WOrec.getFieldValue(‘startdate’);
var enddate = WOrec.getFieldValue(‘enddate’);
var promisedate = WOrec.getFieldValue(‘custbody_promisedate’);
var location = WOrec.getFieldValue(‘location’);
var entity = WOrec.getFieldValue(‘entity’);
var job = WOrec.getFieldValue(‘job’);
var createdfrom = WOrec.getFieldValue(‘createdfrom’);
var sotranid = createdfrom ? nlapiLookupField(‘salesorder’,createdfrom,’tranid’ ): ”;
for (var i = 1; i This is a cached copy. Click here to see the original post.
-
January 12, 2017 at 2:22 pm #5628
khultquistCheck out the API Governance and Script Usage Unit Limits pages in help.
In a client script, you are allowed 1,000 units. Each record created costs 10, each record submitted costs 20, for a total of 30 per record. 1,000 units / 30 units per record = 33 records. So no, there’s nothing wrong with the efficiency of your script.
There are at least two ways to get around this limit:Re-task this as a scheduled script. Use the button mark a checkbox, and schedule the script to look for records with checkbox checked. Pros: your limit is 333 records, higher if you implement nlapiYieldScript(). Cons: the script runs every 15 minutes.
Have the client script loop limited to 30 records, have the user reload the page and instruct them to click the button again. Pros: easy to implement. Cons: kinda hacky. -
January 12, 2017 at 2:32 pm #5629
khultquistAlso, checkout nlapiCopyRecord(type, id, initializeValues), you could reduce your code and future-proof it by copying all field values from the original, then change your quantity and createdfrom fields.
-
January 13, 2017 at 7:40 am #5630
NReddyAlso, we could bypass this exception by overriding getRemainingUsage() of context object as below.
nlapiGetContext().getRemainingUsage = function () { return 1000; }
erictgrubaugh replied on 01/13/2017, 09:23 AM: While this is possible, it is dangerous. Particularly in Client Scripts, this has the potential to break any other executing scripts (think SuiteApps you’ve installed, etc) that may rely on `getRemainingUsage` to guide their behaviour. It could easily lead to runaway scripts and poor performance for your users.
-
January 16, 2017 at 6:58 pm #5631
pcutlerAs others have stated, NetSuite intentionally enforces this 1000-point limit on client scripts.So if you need more than 1000 points, the first option I would consider would be Restlets which are allocated 5000 points. Your button could call a Restlet which would create the work orders.
Finally, if 5000 points is insufficient, then scheduled scripts are the way to go. They support 1000 points per execution and unlimited points if you reschedule or yield the script as necessary. In the 2017.1 release, you will be able to immediately trigger a scheduled script from your client script without the admin role.
erictgrubaugh replied on 01/16/2017, 08:09 PM: Perhaps just a typo, but Scheduled Scripts actually support 10,000 units per execution.
-
January 16, 2017 at 7:16 pm #5632
borncorpI think this is not the right approach as the way you are doing it it makes the browser wait until all the orders have been created and you run into governance issues as well as the browser may freak out because it may think that the page has crashed and if this happens and they refresh the page, the work orders would be duplicated which would lead to more problems. The right way to do this would be by setting up a scheduled job every 15 mins or so (preferrably a map reduce) that identifies the work orders that need to be edited and splits them.
-
AuthorPosts
You must be logged in to reply to this topic.