Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Prevent Duplicate values for Responsibilties

Community Alums
Not applicable

Hi Team,

 

I have a requirement wherein I need to make sure that contact Relationship table if already have any of the mentioned responsibilities , it should not get readded.

 

 

 

Ankur20_0-1713784202269.png

 

Suppose now I create a new record with Contact Relationship with responsibility as "Billing Contact" and "XYZ", the BR is not working, its allowing to create the record.

 

I have written Before Insert BR as follows on sn_customerservice_contact_relationship table:

var gr = new GlideRecord("sn_customerservice_contact_relationship");
    gr.addQuery('company', current.company);
    gr.addQuery('u_authority_role', current.u_authority_role);
    gr.addQuery('contact', current.contact);
    gr.query();
    if (gr.next()) {

        var authroles = current.getDisplayValue('u_authority_role');

        var autrole = authroles.split(',');
        for (var i = 0; i < autrole.length; i++) {
            var role = gr.u_authority_role.getDisplayValue();

            if (role.indexOf(autrole[i]) != -1) {
                gs.addErrorMessage('This contact already has a contact relationship established with this account. For any changes, please edit the existing record.');
                current.setAbortAction(true);
            }
        }
    }
1 REPLY 1

Community Alums
Not applicable

Hi All,


This is fixed. I needed to remove the  line  //gr.addQuery('u_authority_role', current.u_authority_role);