Setting current user in Requested for field

Sandeep Sharma2
Tera Contributor

Hello All, 

I have created a ui action on cmdb_ci table and ordering a catalog item by this button. I am able to set this value as static but not able to set a dynamic value (current logged in user). can anyone suggest me what changes i can made to my code fill "Requested for" field value as current logged in user.

Here is my code segment:-

 

request.setRequestBody("{'sysparm_id':'e08d99ae9713111005827f200153af15','sysparm_quantity':'1','variables':{'requested_for':'62826bf03710200044e0bfc8bcbe5df1','configuration_item':'829e953a0ad3370200af63483498b1ea','description':'Record created from Rest API Explorer'}}");

Thanks in advance

14 REPLIES 14

jaheerhattiwale
Mega Sage
Mega Sage

@Sandeep Sharma2 

'requested_for':gs.getUserID()

 

Replace the requested_for value with gs.getUserID() as above.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hello Jaheerhattiwale,

(As i am not hardcore developer) I have tried this but i guess this can be used while you are "simple coding" but in this case these parameters are in Json form so we need to try some other approach to set values.

@Sandeep Sharma2 You should try following code:

 

var requestBody = {
'sysparm_id':'e08d99ae9713111005827f200153af15',
'sysparm_quantity':'1',
'variables':{
'requested_for': gs.getUserID(),
'configuration_item':'829e953a0ad3370200af63483498b1ea',
'description':'Record created from Rest API Explorer'
}
}

request.setRequestBody(JSON.stringify(requestBody))

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@Sandeep Sharma2 Did you try this?

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023