- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2021 03:13 PM
Hey guys,
I am exploring Batch API
My requirement is , an internal team will post 10000 of Rest Calls per day.
Each Rest Call has around 300 records that has to be inserted to target table . So i cannot use Import Set API , as Import Set API only inserts/updates one record per call .
So I was exploring Scripted Rest API to parse the JSON and then insert to the Import Set table to transform.
There are some reference fields i have to populate and also create a Parent Child Relationships , so i would have to have a transform to build logic .
I also wanted to know about the Batch API .
Lets assume , i provide the Batch API end point to a different team, if they are going to post Rest Calls with multiple records , how is the data being transformed and how can i add logic before i transform data to Target table .
Is Batch API is an upgraded version of Table API with batches of Records ??
Thank You
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2021 09:01 PM
Hi,
you need to send array of json objects
the key would be the column name in import set
Example:
field1 and field2 are the column names of the import set staging table
[
{
"field1":"value1",
"field2":"value2"
},
{
"field1":"value3",
"field2":"value3"
}
]
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
02-17-2021 09:23 PM
Hi Ankur ,
I guess the request body is good
Records are getting created , no issues there , mapping doesn't work
var importSetRowGr = new GlideRecord(this.importSetTable);
importSetRowGr.initialize();
importSetRowGr.setValue('sys_import_set', this.importSetSysID);
importSetRowGr.setValue('sys_import_row', this.importSetRowCounter);
importSetRowGr.setValue('sys_import_state', 'pending');
/*@ARG: Map all the columns in the Request Body to the Import set Columns */
for (var jsonColumn in jsonRow) {
try {
importSetRowGr[jsonColumn] = jsonRow[jsonColumn];
} catch (e) {
gs.log('Unable to import the column ' + jsonColumn + ' Error:' + e.getMessage());
}
}
for (var jsonColumn in jsonRow) {
try {
importSetRowGr[jsonColumn] = jsonRow[jsonColumn];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2021 09:32 PM
Hi,
I believe your staging tables will be having columns starting with u_
so update the body as this
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
02-18-2021 10:35 AM
One last question , how do i add a response body here ? Still i am getting null response , because i dont see a response body code in here .
Should i add in Rest Api Resource or the script include ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2021 09:11 PM
Hi,
if you wish to send response from scripted rest API then it should be in the script section of scripted rest api
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
02-19-2021 11:03 PM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
If not, please let us know if you need some more assistance.
Thanks!
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader