I would like to verify a sc_task field value to determine action in a worklow

ruey
Kilo Contributor

Script for my IF activity in the workflow:

answer = ifScript();

  function ifScript() {

  if (sc_task.u_separation_verification == 'Approved') {

  return 'yes';

  } else {

  return 'no';

    }

  }

Workflow table is sc_req_item.

How can we refer to the sc_task table for the value in the workflow?

Thanks!

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Ruey,



The above script pasted by Abhi should work. I am assuming there will be only one task out of many which has assignment group "Service B". If yes then you can add an additional query based on assignment group.



Additional things to be modified in above code.


  • Change line from the above code to make it work i.e gr.addQuery("parent",current.sys_id); should be gr.addQuery("request_item",current.sys_id);
  • There is a typo error in above code i.e function getTaskInfo()[ should be function getTaskInfo(){


Hence the final code will be


answer = ifScript();




function ifScript() {


  if (getTaskInfo()== 'Approved') { //Make sure Approved is the exact choice value


  return 'yes';


  } else {


  return 'no';


    }


  }




function getTaskInfo(){


var gr = new GlideRecord('sc_task');


gr.addQuery("request_item",current.sys_id);


// add another addQuery condition to filter the exact task you are looking for, this can be based on the task's property...


gr.addQuery("assignment_group.name", 'Service B'); //Make sure Service B is the exact name of the group


gr.query();


if(gr.next()){


      return gr.getValue("u_separation_verification");


}else{


return -1;


}


}








Please let us know if you have any additional question.


View solution in original post

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Ruey,



The above script pasted by Abhi should work. I am assuming there will be only one task out of many which has assignment group "Service B". If yes then you can add an additional query based on assignment group.



Additional things to be modified in above code.


  • Change line from the above code to make it work i.e gr.addQuery("parent",current.sys_id); should be gr.addQuery("request_item",current.sys_id);
  • There is a typo error in above code i.e function getTaskInfo()[ should be function getTaskInfo(){


Hence the final code will be


answer = ifScript();




function ifScript() {


  if (getTaskInfo()== 'Approved') { //Make sure Approved is the exact choice value


  return 'yes';


  } else {


  return 'no';


    }


  }




function getTaskInfo(){


var gr = new GlideRecord('sc_task');


gr.addQuery("request_item",current.sys_id);


// add another addQuery condition to filter the exact task you are looking for, this can be based on the task's property...


gr.addQuery("assignment_group.name", 'Service B'); //Make sure Service B is the exact name of the group


gr.query();


if(gr.next()){


      return gr.getValue("u_separation_verification");


}else{


return -1;


}


}








Please let us know if you have any additional question.


Thanks so much Pradeep.



It is working now.