Will Update work in the Insert Scripted Rest API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 03:00 AM
Hello all,
I have used scripted rest API (Insert), POST method to Insert the data, It worked fine.
There are few records inserted, all good here but later I have added 1 or 2 fields in that table and updated the scripted accordingly, just to update those 2 fields without disturbing the earlier records but the problem here is now records or inserting again as duplicates even though we have check point to stop duplicates.
Update function will not work in the Insert scripted rest API?
Please help!
Thanks,
Ksnow
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 04:13 AM
Hi,
if record is found then it would update
are you talking about this part?
this looks good to me
var vnetSysId;
var grVnet = new GlideRecord("u_cmdb_ci_azure_virtual_network");
grVnet.addQuery("name", vnet.name);
grVnet.addQuery("u_resource_group", rgSysId);
grVnet.query();
// If there is not already a Virtual Network with this name, insert it
if (!grVnet.next()) {
grVnet.initialize();
grVnet.u_resource_group = rgSysId;
grVnet.u_azure_location = locSysid;
grVnet.name = vnet.name;
grVnet.u_azure_subscription = subscriptionSysId;
grVnet.u_active = vnet.u_active;
vnetSysId = grVnet.insert();
} else {
grVnet.u_azure_location = locSysid;
grVnet.u_azure_subscription = subscriptionSysId;
grVnet.u_active = vnet.u_active;
grVnet.setWorkflow(false);
grVnet.autoSysFields(false);
grVnet.update();
while (grVnet.next()) {
vnetSysId = grVnet.sys_id.toString();
}
}
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
‎03-28-2022 04:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 04:32 AM
Hi,
it means your query is not working fine
var grVnet = new GlideRecord("u_cmdb_ci_azure_virtual_network");
grVnet.addQuery("name", vnet.name);
grVnet.addQuery("u_resource_group", rgSysId);
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
‎03-28-2022 04:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 04:50 AM
Just to confirm, will update work in API when we have given it for Insert?