- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 11:02 AM
Hello,
I am using the REST interface to create an incident record. This is working fine except that the Caller field is blank in the new incident. The REST interface does not seem to have a field for "caller", but I do see that there is a field for "caller_id". However, I can't seem to find the caller_id value on a user record. Any pointers would be appreciated.
Patrick
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 11:27 AM
Sort-of. That goes back to what I was saying above - it's a reference field, and SHOWS you the Display value of the sys_id supplied. If the Display Value is distinct, the system should be able to turn that into the sys_id you need, and will work fine, but if you ever end up with more than one "John Smith" in your organization, you're not likely to end up with the right value.
If you look at the incident form as admin, right click and Show XML, it'll show you both the Display Value (string name) and the sys_id, but the true value of the field is the sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 10:55 AM
Through Dot-walking, you can specify which fields you want to receive in the response (sysparm_query and sysparm_fields). But as far as I have come to explore the API, this is not possible when trying to specify where you want to POST your data, which seems to be the problem here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 11:20 AM
It's hard to know exactly how to proceed without knowing more about what you're trying to do, but the rough answer is that you'll probably have to execute a REST call against the sys_user table to retrieve the ID to submit for the REST Post to the Incident.
I know you're on the outside looking in, but basically each record in ServiceNow has a 'sys_id' field that is the unique ID. Anything that's a reference field really wants a sys_id supplied. That said, you may have some success giving it the EXACT display value, but it's much more solid programming to submit using the official sys_id.
If you have a way, that ServiceNow knows that you can positively identify the record (login id would be excellent, if you have access to it), then you can use that in the lookup, and that's best, something like:
https://<<instance name/api/now/table/sys_user?sysparm_query=user_name%3Djcooper_snow&sysparm_limit=1
Will return every field you have access to on that record.
For your purposes, you can limit it to just the sys_id by using:
GET https://<<instance name>>/api/now/table/sys_user?sysparm_query=user_name%3Djcooper_snow&sysparm_fields=sys_id&sysparm_limit=1
Then your response is just:
Response Body
{ "result": [ { "sys_id": "fdf1a9340f22720052e3e388b1050e82" } ] }
Which you use as the caller_id when you push in your incident.
Now if it's done through automation, and it's going to be the same user every time - then you'll just need a system account with permissions to create an incident, and you can hardcode the sys_id for that account. Probably easiest to ask your ServiceNow admin to grab it for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 11:22 AM
I just realized that the value you need to provide is the name attribute of the user record in sys_user. It's confusing to call this parameter caller_id on the incident form. So what you need to do to set a person as the caller is to find their "name" attribute in the users table and take this as a value for "caller_id":
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 11:27 AM
Sort-of. That goes back to what I was saying above - it's a reference field, and SHOWS you the Display value of the sys_id supplied. If the Display Value is distinct, the system should be able to turn that into the sys_id you need, and will work fine, but if you ever end up with more than one "John Smith" in your organization, you're not likely to end up with the right value.
If you look at the incident form as admin, right click and Show XML, it'll show you both the Display Value (string name) and the sys_id, but the true value of the field is the sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 11:42 AM
Josh - Thanks for this! The right click, Show XML sequence allows discovery of the sys_id. This is exactly what was needed. Seems odd and contorted that you have to find an internal database system id in order to define the caller, but it works.
Patrick