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

SandeepSharma2_0-1670403335348.png

Thanks for trying @jaheerhattiwale. There was a issue of concatenation. This is the code which worked for me.  

@Sandeep Sharma2 You can try my code as well. It will also yield you same.

But my code will be easier for you in future maintenance without worrying about the concatenation issue. 

And you can adjust the object easily and then stringify it to add to request body.

 

Please test it once and mark as helpful if it gives you same result

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

newhand
Mega Sage

HI @Sandeep Sharma2 

The below code can get the current logged in user's sys_id (more information - see  LINK )

 

 

gs.getUserID()

 

Please mark my answer as correct and helpful based on Impact.

Hello Newhand,

(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.

Mohith Devatte
Tera Sage
Tera Sage

Hello @Sandeep Sharma2 , try this 

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

Hope this helps 

Mark my answer correct if this helps you 

Thanks