This topic contains 9 replies, has 0 voices, and was last updated by MarkZSSI 8 years, 3 months ago.

  • Author
    Posts
  • #6312

    MarkZSSI

    I have a script that does a transfer between warehouses from an item receipt.

    When it does one line item it says I have 920.0 left. Yes, I ran the below code to tell me the 920.0 was left:

    Code:
    var use = nlapiGetContext().getRemainingUsage();
    response.write(use);
    If I run two line items, it gives me this error. Logically if one line item only depletes it by 80, why does 2 line items totally kill the script with the usage limit error?
    This is a cached copy. Click here to see the original post.

  • #6313

    david.smith

    Can you share more code? You haven’t given us anything to go off of.

  • #6314

    pcutler

    Depends what your logic is for each line item. Instead of tracking your governance usage this way, try hand-counting the number of governance points that your API calls use.

    nlapiDeleteFile nlapiInitiateWorkflow nlapiTriggerWorkflow nlapiScheduleScript nlapiSubmitConfiguration nlapiSubmitFile nlobjEmailMerger.merge()
    20
    A user event script on a standard transaction record type (such as Invoice) that includes one call to nlapiDeleteRecord and one call to nlapiSubmitRecord – – consumes 40 units (assuming no other nlapi calls were made).

    In this case, the user event script consumes 40 units out of a possible 1,000 units available to user event scripts. (See Script Usage Unit Limits for the total units allowed for a user event script.)

    nlapiDeleteRecord nlapiSubmitRecord
    When used on standard transactions: 20

    When used on standard non-transactions: 10

    When used on custom records: 4

    nlapiAttachRecord nlapiDetachRecord nlapiExchangeRate nlapiGetLogin nlapiLoadConfiguration nlapiLoadFile nlapiMergeRecord nlapiRequestURL nlapiRequestURLWithCredentials nlapiSearchGlobal nlapiSearchRecord nlapiSendCampaignEmail nlapiSendEmail nlapiVoidTransaction nlapiXMLToPDF nlobjSearchResultSet.getResults nlobjSearchResultSet.forEachResult
    10
    A scheduled script on a standard non-transaction record type (such as Customer) that includes one call to nlapiLoadRecord, one call to nlapiTransformRecord, one call to nlapiMergeRecord, and one call to nlapiSendEmail consumes 30 units.

    In this case, the scheduled script consumes 30 units out of a possible 10,000 units available to scheduled scripts. (See Script Usage Unit Limits for the total units allowed for a scheduled script.)

    nlapiCreateRecord nlapiCopyRecord nlapiLookupField nlapiLoadRecord nlapiSubmitField nlapiTransformRecord
    When used on standard transactions: 10

    When used on standard non-transactions: 5

    When used on custom records: 2
    Note

    To conserve units, only use nlapiSubmitField on fields that are available through inline edit. For more information, see Updating a field that is available through inline edit andUpdating a field that is not available through inline edit.

    nlapiLoadSearch nlobjJobManager.getFuture nlobjSearch.saveSearch
    5

    nlapiLogExecution
    See Governance on Script Logging.

    nlapiSetRecoveryPoint nlapiSubmitCSVImport nlobjJobManager.submit
    100

    All other SuiteScript APIs

  • #6315

    MarkZSSI

    Here is the code that right now is generating – 985 on how much is left. Now if were to put in a 2nd item receipt, it would say I’m over the limit:

    Code:
    function Qtyupdate(request,response)
    {

    // START count number of warehouses that are not FEN

    var filters = new Array();
    filters[0] = new nlobjSearchFilter(‘name’, null, ‘isnot’, ‘FEN’);

    var columns = new Array();
    columns[0] = new nlobjSearchColumn(‘name’);

    var results = nlapiSearchRecord(‘location’, null, filters, columns);

    wh = results.length;

    nofen = wh – 1;

    // END count number of warehouses that are not FEN

    // START retrieve internal ID from item receipt

    var filters = new Array();
    filters[0] = new nlobjSearchFilter(‘custbody_distributed’, null, ‘is’, ‘F’);
    filters[1] = new nlobjSearchFilter(‘custbody_accellos_rcv’, null, ‘is’, ‘T’);

    var columns = new Array();
    columns[0] = new nlobjSearchColumn(‘item’);
    columns[1] = new nlobjSearchColumn(‘internalid’);

    var results = nlapiSearchRecord(‘itemreceipt’, null, filters, columns);

    for (var i = 1; results != null && i < results.length; i++)

    {
    var result = results[i];

    var itemId = result.getValue('item');
    var ir = result.getValue('internalid');

    //code check
    var use = nlapiGetContext().getRemainingUsage();
    response.write(itemId + "____" + ir + "____" + use);

    /****
    /// Code here to do the item transfer, etc…
    ****/
    }

    }

    }else{
    // POST response

    }
    The above code basically counts the number of warehouses minus the main one that all the items are dumped into once Accellos saves the item receipt. It then searches for the internal ID of the line items, grabs that item internal ID and the item receipt internal ID.

    That only uses 15 out of 1000 – leaving 985. Again, if I were to run a 2nd line, I'd expect it to be 970 left, and not going over.

    Any ideas on how to get this to not go over the NS set limits? Thanks!

  • #6316

    Olivier Gagnon NC

    Is each individual line of the receipt pinging the suitelet/restlet?

    You are probably hitting the script execution limit on the Item Receipt, not from the Suitelet.

  • #6317

    pcutler

    The only two API calls in the snippet you provided that consume governance points are the two calls to nlapiSearchRecord. As Oliver said, the governance is being consumed somewhere else besides the snippet above. If you’re not sure which script is causing the error (possibly restlet or user event triggered by a suitelet) then search the execution log (script note search) and join to “Script Fields…” to see which script is throwing the error.

  • #6318

    JayDP123

    Is it a User-Event script or a Restlet? Restlets have 5000 units allowed rather than 1000. But I would just print the remaining usage wherever I could to find out where the limits are getting used.

  • #6319

    MarkZSSI

    Originally posted by Olivier Gagnon NC

    View Post

    Is each individual line of the receipt pinging the suitelet/restlet?

    You are probably hitting the script execution limit on the Item Receipt, not from the Suitelet.

    How do you check for that? Script limit on the Item Receipt.

  • #6320

    david.smith

    Hey MarkZSSI . Couple things I see in the script you provided. Not sure that it’s causing your errors as the other’s have pointed out but things to be aware of.

    1) Maybe unlikely but your code could fail on your searches if they were to have not results. Try something like this so it will always return an array. Then when you look for results.length your code will not crash.

    Code:
    var results = nlapiSearchRecord(‘location’, null, filters, columns) || [];
    2) Add to your filters

    Code:
    filters[2] = new nlobjSearchFilter(‘mainline’, null, ‘is’, ‘F’);
    This way you’re not looping through the same itemreceipt multiple times without an item.

    3) You can use result.getId() for the internalid so you don’t need that as a column in your search.

    Only do your response.write(….) after all of your other code is complete.

    Also, you might want to consider passing in a parameter for the itemreceipt internalid being transferred. Currently, this is going to search all itemreceipt records with the few filters you have. Or you might add the warehouse location you’re transferring them from.

    The code you have given looks like a suitelet (or part of one). Where is the code that is calling this suitelet?

  • #6321

    MarkZSSI

    Originally posted by david.smith

    View Post

    Hey MarkZSSI .

    The code you have given looks like a suitelet (or part of one). Where is the code that is calling this suitelet?

    Thanks for the tips on the coding. I’m adding that to the coding this morning.

    The code will run as scheduled job (workflow) like every ~30 minutes checking for new item receipts that are saved by Accellos.

You must be logged in to reply to this topic.