Setting current user in Requested for field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 12:48 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 12:57 AM
Thanks for trying @jaheerhattiwale. There was a issue of concatenation. This is the code which worked for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 01:04 AM
@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
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 01:01 AM
The below code can get the current logged in user's sys_id (more information - see LINK )
gs.getUserID()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 08:35 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 01:08 AM
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