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

If this is the case you can easily use create task activity and check the Wait for completion checkbox to proceed to the next activity after the first task is completed.


Yep, but is not flexible, because If i will add in the feature at least 40 records with the different order it will be very hard to maintain:).
I need something flexible, I think I need to use the "run script" activity, but how to check the state of the previous record;)?


This also depends on what logic you want here. Wait for completion checkbox also assumes state value closed incomplete as a complete state.


answer = exitActivity();




exitActivity(){



  var limit = parseInt(gs.getProperty('systemPropertyNameGoesHere')); // set the limit of no of tasks from property



  var cTask = new GlideRecord('sc_task');


  cTask.addQuery('request_item',current.sys_id);


  cTask.addQuery('state','IN','3,4,7');


  cTask.query();


  if(cTask.getRowCount() == limit){ // all the Task have been closed which matches limit


  return 'yes';


  }



  var cTask1 = new GlideRecord('sc_task');


  cTask1.addQuery('request_item',current.sys_id);


  cTask1.query();


  var tillTimeCount = cTask1.getRowCount(); // All tasks assocaited with current RITM



  var cTask2 = new GlideRecord('sc_task');


  cTask2.addQuery('request_item',current.sys_id);


  cTask2.addQuery('state','3,4,7');


  cTask2.query();



  var tillTimeClosedCount = cTask2.getRowCount(); // all Closed Tasks asscoaited with current RITM


  if(tillTimeCount == tillTimeClosedCount && tillTimeCount < limit){ // we need new task to be inserted


  var cTaskNew = new GlideRecord('sc_task');


  cTaskNew.request_item = current.sys_id;


  cTaskNew.insert();


  return 'no';


  }


  return 'no';


}


This should help you.


Requirement here is completely different.