Using scripted rest api new record created instead of skip
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2023 09:48 AM
Hi All,
below is the script that i written to create new records in subnet table using scripted rest api using postman
var requestBody = request.body.dataString;
var parser = new global.JSON();
var parsedData = parser.decode(requestBody);
var subnet = parsedData.subnet;
var subnet = new GlideRecord('cmdb_subnet');
for (var i = 0; i < subnet.length; i++) {
var id = "/subscriptions/" + id + "/subnets/" + subnet[i];
subnet.addQuery('object_id', id);
subnet.addQuery('state', 'Available');
subnet.query();
if (!subnet.next()) {
subnet.initialize();
subnet.name = subnet[i];
subnet.object_id = id;
subnet.insert();
}
}
Using above script if the records not available in table i am able to create new records. but when i pass same data 2nd time at that time also it's creating new record instead of skip. how can i fix
0 REPLIES 0