How to change the state of catalog task using Run Script

ranabiswas
Giga Contributor

Hi All,

I have a requirement where one of the variables will be appearing on the task and RITM and not on the catalog form view. I have been able to do the same. Now next part of the requirement is the variable which is a select box in nature comes with 3 options. This variable is mandatory in task form and the value of it determines the future activities.

Suppose the values are A, B and C.

If A is selected, state of task will get changed to Closed Complete.

If B is selected, state of task will get changed to Closed Incomplete.

If C is selected, state of task will get changed to Closed Complete and a new   task will get created.

Following is my workflow:

find_real_file.png

The script that I have used in my Run Script is:

var ta = new GlideRecord('sc_task');

ta.addEncodedQuery('active=true^request_item='+current.sys_id);

ta.query();

if(ta.next())

{

  ta.state = 3;

  ta.update();

}

It is not updating the task state.

Could you please let me know where I'm wrong and how it can be corrected.

Thank you.

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Rana,



Why not a client script on the table and update the status field? if you wanna do this via Run script then query the task and then fetch the variable value as current.variables.PASS VARIABLE NAME. Based on the choices you can update the task status.


Hi Pradeep,



If I select the option C here, a 2nd catalog task needs to get created. I thought of using client script, however because of this reason I changed my mind.


Could you please let me know how then a 2nd catalog task will get created if I select C, closing the 1st one as Closed Complete.


nitin_kumar
Mega Guru

Hi Rana,



Did you check if the workflow is reaching the Run Scripts? What conditions did you use for the Switch activity?



Thanks,


Nitin.



Hit Like, Helpful or Correct based on the impact of the response


Hi Nitin,



I haven't used any switch conditions here.


The workflow is stuck at the Switch block. Even after selecting any of the values between A, B and C on the task form. the workflow is not moving forward.