Get Sys_ID of Reference Field when POST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 06:57 AM
Hello, I have probably a noob scripting question.
We are testing one of our external systems to create records (Interactions) in ServiceNow. This is working fine however one of the fields that we are trying to push to is a Reference Field (contact). The problem is our external system won't have the name of the person but instead has an ID that would also be on the contact's record.
Since the external system won't have the user's Sys_ID of ServiceNow, how would we pass that unique ID (u_seq_id) to ServiceNow for it to know which name to populate in the Contact field?
Here is a POST sample code:
{
"short_description":"Testing",
"work_notes":"Let's test this",
"assignment_group":"9594fg9rg4g9r9g59g44sd954845f5rfr",
"account":"965985695",
"contact":{
"link": "HTTP://companyname.service-now.com/api/now/table/customer_contact?
u_seq_id=665555",
"value":"sys_id"},
"state":"new"
}
- Labels:
-
Integrations
-
Scripting and Coding
-
Studio

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 07:49 AM
Hi Tramaine,
Through Table API you won't be able to do it, since Table API will receive Table and sys_id as attributes:
Maybe as a possibility you can create your own API to retrieve the customer_contact based on a query (and the query can be based on the u_seq_id or another field). Then you can use it in your post method.
Can this work for you?
Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 08:13 AM
You are going to have to use a Scripted REST API to do this or use a Web service import set.
I prefer the Web service import set for these kinds of things assuming the remote system can make a SOAP call. The reason is there is an import set table and a transform map so its easier to see the data that was sent over and if there are issues for some reason with a record you can reprocess it rather than have the remote system try and make the same call again.
So in your case when using either option you need to simply have them send over the value and do the lookup and record creation yourself.
Web service import set
https://docs.servicenow.com/bundle/sandiego-platform-administration/page/administer/import-sets/concept/c_WebServiceImportSets.html
Scripted REST API
https://docs.servicenow.com/bundle/sandiego-application-development/page/integrate/custom-web-services/concept/c_CustomWebServices.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 09:12 PM
Try use onBefore insert BR and run this logic (Note: I've hardcoded the value). But you can parse the JSON value that you are receive for contact field, as per your payload. Give screenshot for the value that you are getting for the contact field a well below
Result:
Thanks & Regards,
Vasanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 09:38 PM
Hi Tramaine,
I would create a Scripted REST API. u_seq_id can be included with the other data or as a query parameter.