- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2021 09:44 PM
Hi,
I am using the Service Catalog API (namespace : "sn_sc") to create a service request (REQ#) with a request item (RITM#) attached to it using REST API explorer. Below is the request body used ( only mandatory variables for this item is used) ;
{ "sysparm_quantity" : 1,
"variables" : {
"requestor" : "test user",
"project_details" : "test project",
"week_to_unfreeze_time" : "08-03-2021",
"reason_for_unfreeze" : "reason comes here"
}
}
From the above, the request gets created for the user who is sending the request. However, I want to raise this request on behalf of another user. How can this be done?
What I tried :
- Passing the "requested_for" variable both inside and outside of the "variables" field in the request.
- Tried passing the user name and also, the user id in requested_for field.
How can this be done please.
Thanks,
Faiz.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2021 03:34 AM
Please remember this point
1) for reference variable you should always send the sys_id
2) for choice variable always send the choice value
3) for checkbox send true/false
To set the OOB requested_for field on REQ with your user add sysparm_requested_for
{ "sysparm_quantity" : 1,
"sysparm_requested_for" : "4ae3ab0753101200ed11da86a11c0881"
"variables" : {
"requestor" : "UserSysIdHere",
"project_details" : "test project",
"week_to_unfreeze_time" : "08-03-2021",
"reason_for_unfreeze" : "reason comes here"
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2021 03:15 AM
Hi,
Passing the sysparm_requested_for field did not populate the Requested By field. Sending the sys_id in the requestor field inside the variables object populated the Requested By field.
This is json payload that worked;
{ "sysparm_quantity" : 1,
"variables" : {
"requestor" : "sys_id of the user on whose behalf the request is made",
"project_details" : "test project",
"week_to_unfreeze_time" : "08-03-2021",
"reason_for_unfreeze" : "reason comes here"
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2021 03:24 AM
Hi,
OOB there is no BR which would pick value from variable and populate on the requested_for field of REQ.
If you have customization for that then it will work.
But as per screenshot you shared it is requested_for field on REQ which should be set
For that this works well.
Also for reference variable you should always send the sys_id
for choice variable always send the choice value
{ "sysparm_quantity" : 1,
"sysparm_requested_for" : "4ae3ab0753101200ed11da86a11c0881"
"variables" : {
"requestor" : "UserSysIdHere",
"project_details" : "test project",
"week_to_unfreeze_time" : "08-03-2021",
"reason_for_unfreeze" : "reason comes here"
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2021 02:58 AM
Hi,
Thanks for the support everyone. Checking the XML made me understand what's wrong. Passing the sys_id of the user in the requestor field resolved the issue.
{ "sysparm_quantity" : 1,
"variables" : {
"requestor" : "4ae3ab0753101200ed11da86a11c0881",
"project_details" : "test project",
"week_to_unfreeze_time" : "08-03-2021",
"reason_for_unfreeze" : "reason comes here"
}
}
Thanks for helping,
Faiz.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2021 10:59 PM
Hi Faiz,
Can you please verify the field name for "Requested By"? It should be OOB field and its name should be "requested_for". If that is correct the try below code:
var user = GlideUser.getUserByID('sys_id of user'); ///replace sys_id here
{
"variables" : {
"requestor" : "test user",
"project_details" : "test project",
"week_to_unfreeze_time" : "08-03-2021",
"reason_for_unfreeze" : "reason comes here"
},
"sysparm_quantity" : 1,
"requested_for" : user.sys_id.toString(),
"requested_for_display_name" user.getDisplayValue():
};
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2021 11:17 PM
Hi,
the request body only accepts json. Are you meaning to try this somewhere else?