Getting the state of previous task in a workflow

ankit025
Kilo Contributor

Is there a way to get the state of the previous task in a workflow ? Just the previous task, the flow has two tasks on it.

2 REPLIES 2

ohhgr
Kilo Sage
Kilo Sage

Hi Ankit,



You can always   accomplish such task by using a glide record.


e.g.


var scTask = new GlideRecord("sc_task");


scTask.get("req_item", current.sys_id);



var scTaskState = scTask.state.getDisplayValue();




However, since you're using a workflow you can use the workflow_scratchpad variables for this. You can set the value of the task in an after update business rule. And access the same from workflow in the next task.



An example of such script could be found at Accessing the Workflow Scratchpad from Business Rules - ServiceNow Wiki



Thanks,
Mandar


harikrish_v
Mega Guru

Hi Ankit,



I am guessing that you are referring to workflow activities with 'tasks'. If you want to transfer any value from the previous activity to the current activity, then you can use the workflow scratchpad variables for that. You can declare it like this in the previous activity:-


workflow.scratchpad.variableName = variableValue;


And use it like this in the current activity:-


var myValue = workflow.scratchpad.variableName;




If you need the value of some field in the table on which the workflow is running on, you can retrieve it using current.<field_name>



Thanks &   Regards,


Hari