How to restrict duplicate records entry in a table using business rule?

Shubhashis
Kilo Contributor

I have a table:'x_snc_aob_test1_request_baseline_input' .There have 3 fields -Account name(reference field) , Onsite/offshore(choice field) , Baseline input (integer field) .All are mandatory. Here an user can not create another record which has same account name and same onsite/offshore of any previously created records.At that time an error message should be shown -"Invalid insert". So ,how to do?

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

@Shubhashis 

If you want to do with BR only then do with before insert 

Sample logic:

(function executeRule(current, previous /*null when async*/ ) {

    var grP = new GlideRecord("table_name");
    grP.addQuery("field_name", current.getValue("field_name"));
    grP.addQuery("field_name", current.getValue("field_name"));
    grP.query();
    if (grP.hasNext()) {
        current.setAbortAction(true);
    }

})(current, previous);

Hope it helps

 

Thanks,

Murthy

Thanks,
Murthy

View solution in original post

6 REPLIES 6

Sai Kumar B
Mega Sage
Mega Sage

@Shubhashis 

Why Business rule, You can do this without scripting

1.) Go to the Field/Dictionary record and check the "Unique" checkbox, It will not allow duplicates

2.) If you're not able to find the "Unique" checkbox, Configure the form layout and get it on the form

I guess he just wants to prevent duplicate on 2 fields out of 3...

@Jan Cernocky I believe we can apply the same on just two fields

Murthy Ch
Giga Sage

@Shubhashis 

If you want to do with BR only then do with before insert 

Sample logic:

(function executeRule(current, previous /*null when async*/ ) {

    var grP = new GlideRecord("table_name");
    grP.addQuery("field_name", current.getValue("field_name"));
    grP.addQuery("field_name", current.getValue("field_name"));
    grP.query();
    if (grP.hasNext()) {
        current.setAbortAction(true);
    }

})(current, previous);

Hope it helps

 

Thanks,

Murthy

Thanks,
Murthy