- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 12:58 PM
Hi everyone. I was wondering if the following is possible:
I have an API that that is trying to populate the Caller but they are passing me the UserID. Is there any way to automatically match that UsuerID to the correct user in the table? I do not want to have to lookup the sys_id.
Thanks
Solved! Go to Solution.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2022 05:21 AM
Hi Pil,
Caller is a reference field pointing to user table. Because it is a reference, it is returning a sys_id to the user table. The value shown in the Caller field is the column "name" in the user table.
What is the API that is being called? Is it a "Table API" ", "api/now/table/incident"?
To get the user name, would need to call sys_user table to get the name.
api/now/table/sys_user?sysparm_query=sys_id%3D<sys_id>
The other alternative is to create a Scripted REST API.
Script
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var incNumber = request.queryParams.number.toString();
var grIncident = new GlideRecord('incident');
grIncident.addQuery('number', incNumber);
grIncident.query();
if (grIncident.next()) {
var incResponse = {
number: incNumber,
caller: grIncident.caller_id.user_name.toString(),
short_description: grIncident.getValue('short_description'),
description: grIncident.getValue('description')
};
response.setBody(incResponse);
}
})(request, response);
Execution example.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 02:59 PM
You can do this with a scripted REST API.
Caller expects sys_id of user record.
Your scripted REST API should call a script include and script include function need to lookup sys_id based on UserID.
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 03:01 PM
Hi,
Other than not understanding why you can't lookup the sys_id? ...
I recall from some testing and such I was doing before, but there were a few fields which actually would work just fine with information you wouldn't think would. Meaning, I've seen the caller field set with the email of the user, the user_name (User ID), and something else, I forget what it was, but it still worked. It does cause an additional lookup by the server to go resolve it, but if for some odd reason you can't do any other script...for whatever reason...you can give it a shot.
Try setting it with the User ID and it may actually resolve the user itself.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2022 05:21 AM
Hi Pil,
Caller is a reference field pointing to user table. Because it is a reference, it is returning a sys_id to the user table. The value shown in the Caller field is the column "name" in the user table.
What is the API that is being called? Is it a "Table API" ", "api/now/table/incident"?
To get the user name, would need to call sys_user table to get the name.
api/now/table/sys_user?sysparm_query=sys_id%3D<sys_id>
The other alternative is to create a Scripted REST API.
Script
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var incNumber = request.queryParams.number.toString();
var grIncident = new GlideRecord('incident');
grIncident.addQuery('number', incNumber);
grIncident.query();
if (grIncident.next()) {
var incResponse = {
number: incNumber,
caller: grIncident.caller_id.user_name.toString(),
short_description: grIncident.getValue('short_description'),
description: grIncident.getValue('description')
};
response.setBody(incResponse);
}
})(request, response);
Execution example.