- 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 05:52 AM
Hi @Pradeep63 ,
ServiceNow is the target system(Inbound) are you getting the data from the source system which is outbound to that system?
is this your Final JSON?
{
"table":"sn_hr_core_case",
"fields":
{
"hr_service":"xxxxxxxxxxx",
"opened_for":"xxxxxxxxxx",
"short_description":"xxxxxxx",
"description":"Test"
},
"includeErrors":"true"
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 06:07 AM
Yes, ServiceNow is the target system. Source system is a third party system which will initiate the REST call to create HR Case in SNOW.
This is not the final JSON. I am trying to create a HR case with these four fields populated on the case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 06:17 AM
Hi @Pradeep63 ,
Okay.
If you are trying with array json which 1st one use below to get parameters and based on your requirement you can add conditions on scripted REST API using Glide record.
var parameters = request.body.data;
var tablename = parameters.table.toString();
var fieldnames = this.tablename.fields[0];
var hr_service=fieldnames.hr_service.toString();
var opened_for=fieldnames.opened_for.toString();
var short_description=fieldnames.short_description.toString();
var description=fieldnames.description.toString();
2. If you are using 2nd JSON with out array use below on script REST API to get JSON values and Glide based on requirement.
var parameters = request.body.data;
var tablename = parameters.table.toString();
var fieldnames = this.tablename.fields;
var hr_service=fieldnames.hr_service.toString();
var opened_for=fieldnames.opened_for.toString();
var short_description=fieldnames.short_description.toString();
var description=fieldnames.description.toString();
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 06:25 AM
Thanks for your inputs.
Since this is an OOB Scripted REST API from ServiceNow, I dont want to make any customizations. I am checking to see if I can build a JSON Request body such that it will satisfy both the conditions I have mentioned in my question above.
Thanks again for your inputs.