This topic contains 3 replies, has 0 voices, and was last updated by david.smith 8 years, 1 month ago.

  • Author
    Posts
  • #6108

    sklett

    Howdy everyone,

    I have a scheduled script that is processing a few hundred sales orders daily. It *mostly* works fine, but there are 10-15 events a day where the call to nlapiInitiateWorkflow() results in NetSuite throwing a

    RCRD_HAS_BEEN_CHANGED

    exception. I’ve checked and verified there are no updates in my code, it’s a dead simple script, 71 lines most of which are infrastructure and plumbing.

    Considering we can’t pass an nlobjRecord reference to the nlapiInitiateWorkflow() method I don’t see how I can be the cause of a concurrency fault. I’m tempting to put a simple retry mechanism in place but I’d rather understand WHY this is happening first.

    Any ideas?

    As you can see it’s pretty basic:

    PHP Code:

    try {
        var workflowInstanceId = nlapiInitiateWorkflow(order.getRecordType(), order.getId(),
            configurationData.workflowId);

        SPR.UTIL.Log.audit(‘Order Approval Review Initiated’,
            String.format(‘{0} {1} approval review initiated by instance {2}’,
                order.getRecordType(), order.getId(), workflowInstanceId));
    } catch(initWFEx) {
        //  If this is the RCRD_HAS_BEEN_CHANGED error we will handle it and log specifically for it
        if(initWFEx.getCode && initWFEx.getCode().toUpperCase() === ‘RCRD_HAS_BEEN_CHANGED’) {

            SPR.UTIL.Log.debug(‘RCRD_HAS_BEEN_CHANGED Error Encountered’, String.format(
                ‘When initiating workflow for {0} {1} the ‘RCRD_HAS_BEEN_CHANGED’ error occurred.’,
                order.getRecordType(), order.getId()));
        } else {
            throw initWFEx;
        }
    }
    This is a cached copy. Click here to see the original post.

  • #6109

    david.smith

    When is this being run? Are other users in the system with these records open? How about optimistic locking on the records?

  • #6110

    sklett

    Thanks for the reply.Scheduled script – scheduled on demand
    It’s possible, we have hundreds of users. That shouldn’t matter though, I’m not retrieving and then updating the order. If nlapiInitializeWorkflow() IS writing to the target record it should be the same as nlapiSubmitField() which isn’t subject to concurrency issues.
    The record is a Sales Order, I can’t control the locking (as far as I know)

  • #6111

    david.smith

    Can you replace the workflow with script?

    Without seeing what the workflow does it would be hard to tell. I’ve never like mixing scripts with workflows.

    Sorry I’m not much help.

You must be logged in to reply to this topic.