Populating the assigned_to using employee_number via REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 02:29 PM
We are trying to populate the assigned_to when creating an incident record using a post to the table API.
POST https://xxxxxxx.service-now.com/api/now/table/incident
We are able to use the user's name, or email, or user_id to do this, but we want to be able to use the employee_number field.
Example: For the user Abraham Lincoln who is in the Presidents group and has the employee_number of 16 we get the following results.
This works:
{
"assignment_group": "Presidents",
"assigned_to": "abraham.lincoln"
}
This does NOT:
{
"assignment_group": "Presidents",
"assigned_to": "16"
}
Response Body
{
"error": {
"message": "Operation Failed",
"detail": "Operation against file 'incident' was aborted by Business Rule 'Abort changes on group^097174f6db4601109bded2984b96199a'. Business Rule Stack:Abort changes on group"
},
"status": "failure"
}
On the assigned_to field in the incident table we have added the following to the Dictionary Entry Override and it allows us to look up a user on the form by their employee_number, but doesn't work with the API "ref_auto_completer=AJAXTableCompleter,ref_ac_columns_search=true,ref_ac_columns=employee_number,ref_ac_display_value=false"
Any suggestions? Thanks All!
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 02:38 PM
Hi,
The assigned to field is a reference to the sys_user table and so it would expect a sys_id. I'm unsure what your display value (column) is for the sys_user table, but I assume it may be their user_name (User id), which is why using their user_name is working in your first example (as the system is taking that display value and then resolving it in the back-end to a sys_id).
For the second example, it's not going to work with just their employee number (unless that is set as the table's display value (column)).
You'd have to query the sys_user table (GlideRecord) with that employee number, find the correct record and then use that record's sys_id to set the assigned_to.
So something like:
var gr = new GlideRecord('sys_user');
gr.addQuery('employee_numer', 'value_from_payload_here');
gr.query();
if (gr.next()) {
{
//build object here
"assignment_group": "Presidents",
"assigned_to": gr.getValue('sys_id')
//end object
} else {
//build alternate object here
"assignment_group": "Presidents"
//end alternate object
}
Same with the assignment group, that too expected a sys_id, but you're setting it with the display value (column) and so it's allowing it, but really it wants a sys_id.
The ac_ref_column attribute and all that wouldn't matter for the REST API as the attribute is just for client side.
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
03-08-2022 03:01 PM
Hi,
Thanks for marking my reply as Helpful.
If it also helped guide you Correctly, please also mark it as Correct.
Thanks and take care! 🙂
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
03-08-2022 03:03 PM
Hello Allen,
I really appreciate the feedback. Everything you said makes sense to me except for why the user_name field is working, along with email_address, and name fields, but yet the employee_number field does not. I guess I was hoping for a setting in the system that currently contains user_name, email_address, name, then I could just add employee_number. We were hoping we didn't have to query the users table first. By the way, the display field on the sys_user table is name.
Example of the email address working:
{
"assignment_group": "Presidents",
"assigned_to": "abraham.lincoln@example.com"
}
Returns this:
{
"result": {
"assigned_to": {
"display_value": "Abraham Lincoln",
"link": "https://xxxxxx.service-now.com/api/now/table/sys_user/a8f98bb0eb32010045e1a5115206fe3a"
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 04:01 PM
Hi,
I see what you're saying and have also tested this out myself using the REST API Explorer. I feel like I've heard of something like this before, but I'm blanking on what is allowing this, but as you've mentioned, it seems isolated to specific fields. I'm going to try and see if I can pinpoint what's going on here.
Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!