- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 05:37 AM
Hi,
I am trying to create an HR Case through REST API using the Out of the Box Scripted REST API "HR Case Creation" available in ServiceNow HRSD.
I have come up with the below JSON request body for making the REST POST call:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 03:29 PM - edited 01-17-2023 03:33 PM
The correct format for "fields" is specified in the createTask API as "@param fields Object Map of field objects, eg { 'hr_service': { value: 'SYS_ID' } }". This should look like:
{
"table": "sn_hr_core_case",
"fields": {
"hr_service" " { "value": "xxxxxxxx" },
"opened_for": { "value": "xxxxxxxx" },
"short_description": { "value": "xxxxxxx" },
"description": { "value": "xxxxxxx" }
},
Some fields may need additional values in the object besides "value" (the API documentation mentions as "setAsDisplayValue" option), but this should work for most fields.
Your first example did not work as it used array notation ([]) for the "fields" property, when it should just be an object ({}).
Your second example did not work as it used a String ("xxxxx") instead of an object ({ "value": "xxxxx"}) for each field property in "fields" object.
An example JSON from a test instance with test data:
{
"table":"sn_hr_core_case",
"fields":{
"opened_for":{"value":"62826bf03710200044e0bfc8bcbe5df1"},
"subject_person":{"value":"62826bf03710200044e0bfc8bcbe5df1"},
"work_notes":{"value":"xxxx"},
"hr_service":{"value":"6628cde49f331200d9011977677fcf0b"}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 06:31 AM - edited 11-25-2022 06:33 AM
Hi @Pradeep63 ,
I am not sure about OOTB one. But it will not wok for all the JSON formats.
I will suggest refer OOTB APIS but don't change any functionality on that. Understand and Implement for your format.
Based on the JSON format we need to design the Scripted REST API.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 03:47 AM
Hi @Pradeep63 ,
If your issue got resolved close the question by Accepting solution and hit thumb icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 03:29 PM - edited 01-17-2023 03:33 PM
The correct format for "fields" is specified in the createTask API as "@param fields Object Map of field objects, eg { 'hr_service': { value: 'SYS_ID' } }". This should look like:
{
"table": "sn_hr_core_case",
"fields": {
"hr_service" " { "value": "xxxxxxxx" },
"opened_for": { "value": "xxxxxxxx" },
"short_description": { "value": "xxxxxxx" },
"description": { "value": "xxxxxxx" }
},
Some fields may need additional values in the object besides "value" (the API documentation mentions as "setAsDisplayValue" option), but this should work for most fields.
Your first example did not work as it used array notation ([]) for the "fields" property, when it should just be an object ({}).
Your second example did not work as it used a String ("xxxxx") instead of an object ({ "value": "xxxxx"}) for each field property in "fields" object.
An example JSON from a test instance with test data:
{
"table":"sn_hr_core_case",
"fields":{
"opened_for":{"value":"62826bf03710200044e0bfc8bcbe5df1"},
"subject_person":{"value":"62826bf03710200044e0bfc8bcbe5df1"},
"work_notes":{"value":"xxxx"},
"hr_service":{"value":"6628cde49f331200d9011977677fcf0b"}
}
}