- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 01:58 AM
Hi,
I need to get to grips with ServiceNow's Table API.
In order to better understand, I have created and validated PowerShell code.
In the PowerShell code, if I set up the following, adding a record to ServiceNow is successful. (Sample ①)
The "u_kansen_key" field is also populated with a value.
("u_kansen_key" field is a reference type field.)
----------------------------------------------------------------------------------------------------------------------------------------------------
Sample ①
~ The endpoint uri, etc. is written here.
# Specify HTTP method
$method = "post"
# Specify request body
$body = "{`"u_kansen_key`":`"TEST`",`"u_mind_kanri_no`":`"testInsert07`"}"
# Send HTTP request
$response = Invoke-RestMethod -Headers $headers -Method $method -Uri $uri -Body $body
----------------------------------------------------------------------------------------------------------------------------------------------------
However, if I do the following, the record is added, but the "u_kansen_key" field is empty.
("u_kansen_key" field is a reference type field.)
----------------------------------------------------------------------------------------------------------------------------------------------------
Sample ②
~ The endpoint uri, etc. is written here.
# Specify HTTP method
$method = "post"
# Specify request body
$body = "{`"u_kansen_key`":`"Mr.IP 東北`",`"u_mind_kanri_no`":`"testInsert07`"}"
# Send HTTP request
$response = Invoke-RestMethod -Headers $headers -Method $method -Uri $uri -Body $body
----------------------------------------------------------------------------------------------------------------------------------------------------
Why is there no value in the "u_kansen_key" field in the case of sample ②?
Does anyone know how I can succeed?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2022 04:07 AM
Hi again,
Was able to send Japanese key and save it in ServiceNow table with reference using PowerShell
It's a problem with PowerShell. It's necessary to encode the data as utf8 and send it as bytes as below.
# Specify HTTP method
$method = "post"
# Specify request body
$body = "{`"u_kansen_key`":`"Mr.IP 東北`",`"u_mind_kanri_no`":`"testInsert07`"}"
$bytes = [System.Text.Encoding]::UTF8.GetBytes($body)
# Send HTTP request
$response = Invoke-RestMethod -Headers $headers -Method $method -Uri $uri -Body $bytes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 05:39 AM
Hi
if you specify a text value for a reference record, this would mean that you want to reference a record in the target table whose display name value is "Mr.IP 東北". Are you sure that such a record exists in the target table?
The better approach for creating references is using the Sys IDs for the respective records in the target table.
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 09:24 PM
The display value "Mr.IP 東北" does indeed exist in the referenced table.
As a background, I originally thought that I had to use sys_id to populate the reference type field externally.
However, as shown in this case, I found that even if the display value is specified, there are cases where input can be performed and cases where it cannot be performed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 09:48 PM
Hi,
if you plan to send the display value for that field ensure you include sysparm_display_value=true in the parameter
OR
you can include sysId of the record directly
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 08:27 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader