Script for setting approval from catalog item variable on REQ

Kifrez
Kilo Guru

Hi everyone,

How do you set approval in workflow?

I would like to set the approver to be from variable?
the catalog item variable is manager and value will be from manager field.

Thanks in advanced.

1 ACCEPTED SOLUTION

If this workflow is on request then you should query the RITM details and use them

somethink like this.

var answer=[];
var grScReqItem = new GlideRecord('sc_req_item');
grScReqItem.addEncodedQuery("request="+current.sys_id+"^cat_item=1391a4db070630100b36f6fd7c1ed0c2");//map you catalog item sysid here.
grScReqItem.query();
if (grScReqItem.next()) {

answer.push(grScReqItem.variables.manager.toString());
}
    

 

for below line you should modify the highlated part with the catalog item sysid you want to fetch manager details from.

grScReqItem.addEncodedQuery("request="+current.sys_id+"^cat_item=1391a4db070630100b36f6fd7c1ed0c2");


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

20 REPLIES 20

Monika13
Giga Expert

In workflow approval activity, you can write something like this:

var manager=current.variables.manager;
answer=manager;

hi Monika, this doesn't seem to work. Do you have another idea?

Shikha puri
Tera Contributor

Use the below code under workflow approval activity.

 

answer = [];

answer.push(current.variables.variable-name.sys_id);

 

where variable name is backend value of variable like If i created Manager Variable so I use backend name of variable manager then the code will be :

 

answer = [];

answer.push(current.variables.manager.sys_id);

Hi Shikha, this doesn't seem to work. Do you have another idea?