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

Patrick DeCarl1
ServiceNow Employee
ServiceNow Employee

Ruey,



You will need to do a glide record look up from "sc_task" task table where "request_item" == current.sys_id. then you can run your script with data you pull back.


Hi Patrick,



Where do I set up the glide record script? I put it in the IF activity with my IF statement and it is not working.



Thanks.



Regards,


Ruey


adiddigi
Tera Guru

Ideally.. a Requested Item can have multiple tasks.. So you need a way to differentiate which task you are trying to fetch..


The second point that you should be sure of is, if the task you are trying to fetch in the Requested Item workflow, should already be created by the time this IF activity runs. You can only be sure of that, by putting a waitfor looking to see if that task got created.



Now finally, when you are sure of both the items above, you can do the following:



function ifScript() {


  if (getTaskInfo()== 'Approved') {


  return 'yes';


  } else {


  return 'no';


    }


  }




function getTaskInfo()[


var gr = new GlideRecord('sc_task');


gr.addQuery("parent",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.query();


if(gr.next()){


      return gr.getValue("u_separation_verification");


}else{


return -1;


}


ruey
Kilo Contributor

Thanks for your reply Abhiram.



The task is before the IF script. Do i still require to add the additional query condition?


If yes, can I do it based on Assignment group = "Service B"? (the task has a fulfilment group already hard coded in the task within the workflow)



Sorry I'm not very good with scripting.



Thanks again.