- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 03:23 PM
Im stuck with a Scripted Rest API. I am going to be posting JSON to ServiceNow via powershell. I would like to have one POST but with Multiple records like so
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 02:35 PM
Anyone looking to loop through a Scripted Rest message to update an import set table, With the help of Mike and Pradeep, this is working for me, modify for your needs
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var sn;
var bios;
var requestBody = request.body;
var requestString = requestBody.dataString;
var parser = new JSONParser();
var result = parser.parse(requestString);
//gs.log("******", result);
for (var i = 0; i <result.length; i++) {
sn = result[i].u_serial_number; // Device Serial Number
bios = result[i].u_bios_password; //New PW to update
var record = new GlideRecord('tablename');// Staging table name
record.initialize();
record.u_serial_number = sn;
record.u_bios_password = bios;
record.insert();
}
return {
"response": "Successfully saved request into " + request.pathParams.tablename + " table.",
"requestString": result
};
})(request, response);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 03:10 PM
I have seen this and am a little confused, How can i ensure that the coalesce field is populated on insert?
I am sending a postman request like so
{"u_serial_number":"B4FQQTR13","u_bios_password":"1312456741215e"}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 02:35 PM
Anyone looking to loop through a Scripted Rest message to update an import set table, With the help of Mike and Pradeep, this is working for me, modify for your needs
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var sn;
var bios;
var requestBody = request.body;
var requestString = requestBody.dataString;
var parser = new JSONParser();
var result = parser.parse(requestString);
//gs.log("******", result);
for (var i = 0; i <result.length; i++) {
sn = result[i].u_serial_number; // Device Serial Number
bios = result[i].u_bios_password; //New PW to update
var record = new GlideRecord('tablename');// Staging table name
record.initialize();
record.u_serial_number = sn;
record.u_bios_password = bios;
record.insert();
}
return {
"response": "Successfully saved request into " + request.pathParams.tablename + " table.",
"requestString": result
};
})(request, response);