How to stop creating duplicate ci Relationship records ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 09:58 AM
Hi Everyone,
How to stop creating duplicates for (Patches::Patched by) Ci relationship records, whenever new record is inserted when Runs on::Runs Record created, If already there is a (Patches::Patched by) record then updated with new CI relationship record. for this I wrote After, Insert Business rule. It doesn't work as expected. Can anyone please suggest me a solution.
Business Rule:
var patches = gs.getProperty('cmdb.rel.patches_on_Patched by_type');
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('parent', current.parent);
gr.addQuery('child', current.child);
gr.addQuery('type', 'patches'); //694c4c9a1ba1645870b464e22a4bcbd6 (Patches::Patched by)
gr.setLimit(1);
gr.query();
if (!gr.next()) {
var gr1 = new GlideRecord('cmdb_rel_ci');
gr1.initialize();
gr1.parent = gr.parent;
gr1.child = current.child;
gr1.type = 'patches';
gr1.insert();
} else {
current.setAbortAction(true);
}
Thanks
Venugopal s
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 08:18 PM
Hi,
the BR should be before Insert to abort the insert
why are you inserting using gliderecord?
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
09-15-2022 11:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2022 12:12 AM
Hi,
are you sure the BR triggers and the condition is getting satisfied
what logs did you add?
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
09-16-2022 01:45 AM
Hi
Thanks