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

Voona Rohila
Kilo Patron
Kilo Patron

HI Freddy

are you using proper variable name ?

You should use below coode in 'Approval - user' activity.

 

answer=[];
answer.push(current.variables.u_manager.toString()); //give your manager variable name

Can you also check if manager details are filled or not?


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

Hi Rohila,

 

Yes, the variable name is manager and is part of variable set called user_profile_set

answer = [];
answer.push(gr.variables.manager.toString());

 

find_real_file.png

Hi freddy

there is a mistake in your code,You cannot use gr as it is not defined.

use current to access the details of current record.

code:

answer=[];
answer.push(current.variables.manager.toString()); //give your manager variable name

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

Hi Rohila,

Thanks for your responses.

I've changed it to current.variables.manager.toString()

answer=[];
answer.push(current.variables.manager.toString());

 

Still doesn't work.

 

So far it only works, if I add a user , it works

Hi 

Manager is a refernce field right? can you keep logs and verify manager value.

you can also try this, both will work

answer=[];
answer.push(current.variable_pool.manager.toString());

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