- 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-09-2022 09:51 PM
$bytes = [System.Text.Encoding]::UTF8.GetBytes($body)
I have tried this and can confirm my success.
I didn't realize it was a PowerShell-only issue.
I am glad to know this this time.
Thank you very much.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 01:49 AM
Koki,
Ankur's advise on setting "sysparm_display_value=true" worked in my instance. I was able to insert a reference field into my table.