How to stop creating duplicate ci Relationship records ?

Community Alums
Not applicable

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);
    }

 

find_real_file.png

 

Thanks 
Venugopal s

@Mark Roethof @Chuck Tomasi @Ankur Bawiskar @Mahendra @Mohith Devatte 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the BR should be before Insert to abort the insert

why are you inserting using gliderecord?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

Hi @Ankur Bawiskar ,

I have changed to before insert and insert() has been removed, but still empty records are inserting.

Thanks
Venugopal S
find_real_file.png

Hi,

are you sure the BR triggers and the condition is getting satisfied

what logs did you add?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

Hi @Ankur Bawiskar conditions are matching, Runs:onRun records are inserting but patches CI relationships are getting empty. 

Thanks