How to send User field detail via REST API for a catalog item ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 03:37 AM
Hi Community,
I am creating a catalog item request via REST API.
I used below method in REST API Explorer:
Namespace: sn_sc
API Name: Service Catalog API
POST Method: Buy Item
Request Body:
{
"sysparm_quantity": "1",
"variables":
{
"employee_to_offboard": "David Anderson",
"offboard_type": "Retirement",
"employment_end_date": "2024-03-22",
"notice_period": "90"
}
}
Request is being created successfully but the field "employee_to_offboard" which is Reference field for User table is not populating via this method.
If use sys_id then it works, but I need to send this payload for third party applications who only has access to user names and not sys_ids.
Could you please suggest me how can we populate user field by user name instead of sys_id ?
Thanks in Advance,
Hritik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 04:26 AM
Hi @Hritik I assume in that case you need to retrieve user name response and do the glide record on user table and match the user name with username and return the sysid to insert.
your third party tool should handle this.
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 04:06 AM
Hi @Harish KM
Could you please let me know what exact steps the third party needs to do to get sys_id ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 05:25 AM - edited 02-02-2024 05:38 AM
Hello Hritik,
If you don't want to do any additional configuration/development this should be treated in the 3rd party application and then call post method using the proper sys_id. However, I think that if you follow this steps you'll be able to change that value (Although, as I said it's not the best way):
1) Create a business rule onBefore on sc_item_option table, this table stores instantiation of values from variables in RITM. Retrieve data before it goes blank when try to insert name instead of sys_id
2) Be strict with conditions for avoiding triggering anything unnecessarily, in this example I've selected the field in the table, in my case question = requested for (pay attention to item:
3) I've just added a simple script in advanced for changing this value querying sys_user table:
var userName = current.value;
var grUser = new GlideRecord('sys_user');
grUser.addQuery('name', '=', userName);
grUser.query();
if (grUser.next()) {
grUser.getUniqueValue();
}
current.value = grUser.getUniqueValue();
This is configured only for insert action, if further actions it's required try to achieve this being more restrict with conditions and filters.
☆ Community Rising Star 22, 23 & 24 ☆
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 05:12 AM
Hi @Hritik
It expects you to pass sys_id instead of display name to the field "employee_to_offboard" . For getting the sys_id, you could make use of another REST API call on sys_user table as below :
This API call will return the user record sys_id which you can pass to your Buy Item API.
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.