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

  • Author
    Posts
  • #10243

    sklett

    Hello everyone,

    I have a catch-22 situation here and I’m looking for any ideas or approaches that I may be missing.

    Scenario:

    When a Sales Order is reverted from Pending Fulfillment to Pending Approval as a result of a user editing the sales order who lacks the Approve Sales Order permission – in other words when they edit the order it reverts it back to Pending Approval. In this scenario the NetSuite application “changes” the Status field value and you can only pick up this change in an AfterSubmit context, even worse you need to hit the DB for a fresh read of the field to catch the change (i.e. nlapiGetFieldValue() will return the original, unchanged value)

    In this scenario I need my workflow to evaluate it’s transitions and transition back to a “Pending Approval” state.

    Problem:

    There are actions in my Pending Approval State that update fields on the sales order, of course this means the WF must transition on BeforeSubmit. But it can’t because it will only pick up the Status change in AfterSubmit.

    So I’m stuck!

    NetSuite has provided a mechanism to handle similar situations with defined event types. For example the APPROVE event allows your workflow to run in a BeforeSubmit context and thus supports changing fields on the record. There is no “Unaproved” event, there is “REJECTED” which sounds promising but is not related to the sales order transitioning from approved the pending approval.

    Simple Question:

    How can a workflow transition on a sales order changing to Pending Approval and update fields on the sales order?

    Things I’ve Tried:

    I tried to use nlapiTriggerWorkflow() in a UE but quickly learned that it needed to be AfterSubmit to pick up the Status change. Of course when you trigger a workflow from a script it will run in the context of the script (i.e. AfterSubmit) and this doesn’t work.

    Other Possible Solutions I’ve come up with:Running the workflow in a scheduled mode, I’ve never used a scheduled workflow but I have the feeling that when executed in scheduled context you can write to the record. This solution is unacceptable because we need near realtime response to the status change to Pending Approval, we can’t wait for the scheduled execution to fire.
    Any suggestions will be greatly appreciated and eagerly explored!

    -Steve

    PS: Just noticed I’m a “Junior Member” – what’s it take?!
    This is a cached copy. Click here to see the original post.

  • #10244

    rnedelkow

    Steve, the titles and ranks had to be updated so you’ll need to refresh the page. Thanks for the heads up.

  • #10245

    khultquist

    Interesting problem…

    This is kind of roundabout, but what about making a custom checkbox on the record, let’s call it ‘Record was updated’. Anytime the record is edited, this checkbox is checked automatically (by script or workflow, beforesubmit).

    Then have a workflow evaluate only orders with the checkbox checked, aftersubmit. The workflow changes fields as necessary. After evaluation, the WF unchecks the checkbox.

  • #10246

    evan_goldberg

    Seems wrong that the sales order reverts? Have you reported this to support?

  • #10247

    sklett

    Huh! And here I thought it was a nice feature (though it should be a preference). Case #2119422 created requesting confirmation on behavior.

  • #10248

    evan_goldberg

    I am not sure – I can see arguments both ways, I guess…

  • #10249

    Olivier Gagnon NC

    Evan and Steve, would the reverting not be caused by the preferences to require re-approval when SO is edited, in Accounting Preferences (I think)? What Im supprised about is that it wouldn’t revert for those that have approval permission.

    Two thoughts, not entirely pleasant, but short of a fix to the state only being returned in After Submit (and I’ve seen that several time myself), then I’m thinking:

    A) Maybe untick the preference to revert SO to Pending Approval, and replicate that behaviour with a script or workflow. The fact the change will occur by script may cause the status change to be picked up by before submit?

    B) Obvious and probably not something you’ll want to do, but take all your Workflow and record it as UE scripts.

  • #10250

    j.j

    I had a similar issue and resolved using oldrecord and newrecord comprisions – basically i transition back to a pending approval state – you can configure the same state so that workflow sets the appropiate values – in case you want to treat it differently than create a separate state called reapproval and set fields and actions as per that. Note that I do check and verify if its a revised SO or a new one by comparing old and new record values. In fact I send it for re-approval only if total or department field is changed. Hope these pointers help.

  • #10251

    sklett

    Thanks for the reply Olivier

    Originally posted by Olivier Gagnon NC

    View Post

    Evan and Steve, would the reverting not be caused by the preferences to require re-approval when SO is edited, in Accounting Preferences (I think)? What Im supprised about is that it wouldn’t revert for those that have approval permission.

    I didn’t realize this was a preference, I had always thought this was built-in behavior, thanks for the tip.

    Originally posted by Olivier Gagnon NC

    View Post

    Two thoughts, not entirely pleasant, but short of a fix to the state only being returned in After Submit (and I’ve seen that several time myself), then I’m thinking:

    A) Maybe untick the preference to revert SO to Pending Approval, and replicate that behaviour with a script or workflow. The fact the change will occur by script may cause the status change to be picked up by before submit?

    This is likely the direction I will need to go in. It’s pretty simple to do and creates minimal maintenance burden. It’s always a bummer when you need to circumvent or reproduce native behavior.

    Originally posted by Olivier Gagnon NC

    View Post

    B) Obvious and probably not something you’ll want to do, but take all your Workflow and record it as UE scripts.

    Yes, I’d rather not revert to script. I’m making a real effort to use Workflows for situations where they *seem* like a good fit. But when you run into situations like this it makes you question the decision.

    Thanks for the reply and input.

  • #10252

    sklett

    Originally posted by j.j

    View Post

    I had a similar issue and resolved using oldrecord and newrecord comprisions – basically i transition back to a pending approval state – you can configure the same state so that workflow sets the appropiate values – in case you want to treat it differently than create a separate state called reapproval and set fields and actions as per that. Note that I do check and verify if its a revised SO or a new one by comparing old and new record values. In fact I send it for re-approval only if total or department field is changed. Hope these pointers help.

    Thanks for the input.

    You aren’t evaluating the status field of old/new records, are you? Do you mean you are looking for general field changes between records and transitioning to re-approval if edited? I ask because you can’t rely on the status of the new record as it will not contain the value that may have been changed by NetSuite’s logic.

You must be logged in to reply to this topic.