This topic contains 5 replies, has 0 voices, and was last updated by borncorp 7 years, 7 months ago.

  • Author
    Posts
  • #5627 Score: 0

    Vesku1980
    • Contributions: 0
    • Level 1

    Hello,

    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 < = newcount;i++) { console.log('starting_'+i) var usage = nlapiGetContext().getRemainingUsage(); console.log('usage_'+i+'_'+usage); var NEWwo = nlapiCreateRecord('workorder',{recordmode: 'dynamic'}) var y = i+1 var detailedinformation = sotranid+'_'+y+'/'+count NEWwo.setFieldValue('quantity',1); NEWwo.setFieldValue('assemblyitem',assembly); NEWwo.setFieldValue('units',units); NEWwo.setFieldValue('trandate',trandate); NEWwo.setFieldValue('orderstatus',orderstatus); NEWwo.setFieldValue('firmed',firmed); NEWwo.setFieldValue('startdate',startdate); NEWwo.setFieldValue('enddate',enddate); NEWwo.setFieldValue('custbody_promisedate',promise date); NEWwo.setFieldValue('location',location); NEWwo.setFieldValue('entity',entity); NEWwo.setFieldValue('job',job); NEWwo.setFieldValue('custbody_mpc_wosplit_info',de tailedinformation); NEWwo.setFieldValue('custbody_mpc_sonumforprinting ',sotranid); NEWwo.setFieldValue('custbody_mpc_wonumforprinting ',+y+'/'+count); try { var NEWwoId = nlapiSubmitRecord(NEWwo); nlapiLogExecution('Audit', 'Created WO', +NEWwoId); } catch (e) { console.log(e) //nlapiLogExecution('ERROR', 'Work Order creation error', e.getCode() + 'n' +e.getDetails()); } } nlapiSubmitField('workorder',id,'quantity','1') nlapiSubmitField('workorder',id,'custbody_mpc_wosp lit_info',sotranid+'_1/'+count) alert(+newcount+'work orders created!') } window.self.location.reload(false); }
    This is a cached copy. Click here to see the original post.

  • #5628 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    Check 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.

  • #5629 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    Also, 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.

  • #5630 Score: 0

    NReddy
    • Contributions: 0
    • Level 1

    Also, 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.

  • #5631 Score: 0

    pcutler
    • Contributions: 0
    • Level 1

    As 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.

  • #5632 Score: 0

    borncorp
    • Contributions: 0
    • Level 1

    I 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.

You must be logged in to reply to this topic.