Search code examples
servicenow

How to get the current catalog task stage or determine the next stage?


In ServiceNow on the Workflow Editor, I have a Catalog Task with the Stage defined as "Processing" and an Advanced script to do some pre-work. When I call current.stage it gives me the stage for the previous state as the stage isn't set to the task's defined stage value until the task is completed.

Current stages in order: Processing, Assignment, Assessment, Closure.

Example: On the "Assignment" task when you call the current.stage in the Advanced script it will return "Processing".

How do I get the stage for the task so if I'm on "Assignment" that I can get "Assignment"?

I had the idea of querying the wf_stage table to determine the next stage but when I call current.workflow_version it's not defined.


Solution

  • I wonder that in the workflow, since the position of activity where you call current.stage is fixed and won't change once decided, why not just using the hardcoded stage name, without calling current.stage or other functions?

    Also I have an another idea, just for your reference. How about putting an array containing all stages into the scratchpad in a Run Script at the beginning of the workflow?

    workflow.scratchpad.myStages = ['Process', 'Assignment', 'Assessment', 'Closure'];
    

    And then you could get the next stage by searching the array afterwards.

    var myStages = workflow.scratchpad.myStages;
    var currentStage = myStages[myStages.indexOf(current.stage) + 1];