The CreatorCon Call for Content is officially open! Get started here.

Change Task creation via workflow script

Arthur7
Tera Contributor

Hello,

I want to create the change tasks creation via workflow (run script activity).
How to check if previous record has the completed state??

an example: I have an additional table which contains the information for the purpose of task creation, I have 3 columns ( Order, Short_description, Assignment Group).

I want to create the change tasks based on information from the table. The issue is, that the task should be created, if the previous task has the state = completed.
Does anyone know how to achieve it?

Thanks in advance for any answers!!!

BR
AS

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

As I said if you are using run script activity to   create a task. Use scratchpad variable as shown.


var task= new GlideRecord('sc_task');


task.initialize();


..


..


..


workflow.scratchpad.taskID=task.insert();



Now in your next activity before creating a task, check if the previous task is completed or not


var task= new GlideRecord('sc_task');


task.get(workflow.scratchpad.taskID);


if(task.state=='completed choice value'){


//insert task here


}


View solution in original post

15 REPLIES 15

Above code should also work in wait for condition activity 🙂 I did not read about the custom table, in this case, limit can be set via custom table no of records count. But the above logic should work, it does not create a new task unless previous task in closed 🙂


Abhinay Erra
Giga Sage

As I said if you are using run script activity to   create a task. Use scratchpad variable as shown.


var task= new GlideRecord('sc_task');


task.initialize();


..


..


..


workflow.scratchpad.taskID=task.insert();



Now in your next activity before creating a task, check if the previous task is completed or not


var task= new GlideRecord('sc_task');


task.get(workflow.scratchpad.taskID);


if(task.state=='completed choice value'){


//insert task here


}


I will do that!!, thx!


There is supposed to be 'N' number of tasks being created which needs the previous one to be completed and I don't see how this code will do that.


We only need to check the previous task. If it was completed then set the


workflow scratchpad variable to the current task id. Or else rollback to


the same script



On Monday, September 5, 2016, kalai <community-no-reply@servicenow.com>