Set Requested Item value from a variable

Ankita23
Tera Contributor

I have a catalog item to increase Priority of any other requests. I have a reference variable to sc_req_item. What I need here is once the request is approved priority of the selected Item (item on the variable) should go 1 level up. So if request is Medium, it should be set to High. If it is High, it should go to Critical.

Addition to that I want to add worknotes also -"Priority has been increased based on ticket XYZ." and details of a variable.

Can anyone please give any input on what workflow scripts should be written to achieve the same?

1 ACCEPTED SOLUTION

Hello Ankita,


In run script activity try below logic.



I have used "medium" and "critical" for example. You can use actual values there.



var ritm = current.variables.u_openedRequests;


var gr = new GlideRecord('sc_req_item');


if(gr.get(ritm)){


if (gr.priority =="medium")


      gr.priority = 'critical';


else if ( same condition with different values)



else if( same condition with different values)



gr.update();


}



Hope it helps.



Kind Regards,


Jotiram


View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Ankita,



I'm assuming you want to calculate this on workflow at requested item level. You can use "Run script" activity in the workflow and the script will be something like.



if(current.request.state == 'PASS CHOICE VALUE HERE')


{


current.priority == 'PASS PRIORITY CHOICE VALUE HERE';


}



P.S: If you don't see priority getting updated directly then try to set impact and urgency value


Hi Pradeep,



I have a reference field on the catalog item which is pointing to ''sc_req_item'' table. PFA same.


Item.png


I want to change the priority of the selected RITM not the current created one. And have to increase the priority of this selected RITM.


I am using the below script to get the value of the same, but it seems not working-


answer = ifScript();

function ifScript() {


if (current.variables.u_openedRequests.priority == '2') {


return 'yes';


}


return 'no';


}



Thanks in advance,


Ankita


Hello Ankita,


In run script activity try below logic.



I have used "medium" and "critical" for example. You can use actual values there.



var ritm = current.variables.u_openedRequests;


var gr = new GlideRecord('sc_req_item');


if(gr.get(ritm)){


if (gr.priority =="medium")


      gr.priority = 'critical';


else if ( same condition with different values)



else if( same condition with different values)



gr.update();


}



Hope it helps.



Kind Regards,


Jotiram


Thanks Jotiram!



It worked.