This topic contains 4 replies, has 0 voices, and was last updated by michoel 8 years ago.

  • Author
    Posts
  • #1575

    sundeepkotamreddy

    Hi,

    We are using an After Save User Event script on an Opportunity record to call the Schedule script, but when there are multiple users trying to create an opportunity we are having issues.

    Example for the issue:Opportunity A & B are saved at the same time, in this case one of them executes and the other should go in to the scheduled script queue.
    But only one opportunity was triggered and the other never went into the scheduled script queue.
    Requirement:The requirement is to call the scheduled script on save of the each opportunity record, but when there are multiple opportunities saved at the same time the trigger for them should be moved into the scheduled script queue.
    We will be importing opportunities using a .csv
    Note:We are using multiple Deployments for the Schedule Script.
    Deployment ID is not used for calling the script.

    Any help is much appreciated…
    This is a cached copy. Click here to see the original post.

  • #1576

    chanarbon

    HI sundeepkotamreddy ,

    For this concern, you may use the N/task module to perform the scheduling using SuiteScript 2.0. This module has the type ScheduledScriptTask that you could use to trigger the functionalities

  • #1577

    robert.paulson

    Hi sundeepkotamreddy ,

    Great question. I suggest creating two deployments for your scheduled script:Both with a status of Not Scheduled.
    If you use multiple queues, make sure that the two deployments are using the same queue.
    Make sure that your nlapiScheduleScript() API call does not specify a deployment ID. That way, the first โ€œfreeโ€ deployment will be used.

    You might need to change the design of your scripts:The after submit user event script will need to flag the opportunity record as “to be processed” (that will be a new checkbox field on your opportunity record).
    I assume that your scheduled script is currently taking, as a parameter, the opportunity’s internal ID that triggered the scheduled script. Instead, you will need to fetch all opportunities flagged as “to be processed” with a scripted search.
    The scheduled script’s logic will need to be placed in a for loop, so that it is applied for each opportunity found in the scripted search.

    Having two deployments will prevent opportunity records to “fall in between the cracks”:The first time an opportunity gets created/updated, the first scheduled script deployment is triggered and will catch that single opportunity.
    If there is a second opportunity created while the first scheduled script deployment is running, it will trigger the second deployment, and put it in the queue.
    All opportunities created before the first deployment of the scheduled script runs the scripted saved will be fetched.
    Opportunities created after the first deployment of the scheduled script runs the scripted search will be fetched when the second deployment runs.
    The first opportunity created after the first deployment is complete will trigger another deployment to be scheduled.
    I hope this helped,

    – Robert

  • #1578

    david.smith

    I’ve developed a queue for schedule scripts. It works really well but you had to include the method in your scheduled scripts. This allowed for multiple calls to trigger a scheduled script and had no limit.

  • #1579

    michoel

    If you don’t need to higher usage limits of a Scheduled Script, another option could be to use a Workflow Action Script and triggered with nlapiInitiateWorkflowAsync()

You must be logged in to reply to this topic.