About "POST" in Table API

Koki
Tera Contributor

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?

 

 

1 ACCEPTED SOLUTION

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

View solution in original post

11 REPLIES 11

Maik Skoddow
Tera Patron
Tera Patron

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

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.

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Koki 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader