duplicate check for multiple fields

Kajal16
Kilo Contributor

hello 

i want to apply duplicate check for multiple fields in such a way if one field id is same for two fields then it will go for another three field checking and if these fields match then it will pop up a message for user already exist. Here i applied a bussiness rule where it is correctly working for one fields but when i apply code for another fields it takes values in the table with that also shows that invalid insert.Kindly give solution for this.

thanks 

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kajal,

If combination of 2 or 3 fields should be unique then you can rather set them as unique at dictionary level

ServiceNow will out of the box show invalid insert

but if you are trying to do this using before insert business rule then is it not working? can you share the script here?

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

 The script is here.I applied this for scoped application.

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

// Add your code here
var grAst = new GlideRecord('table_name');


grAst.addQuery('roll_number', current.roll_number);
grAst.addQuery('name', current.name);
grAst.addQuery('address', current.address);
grAst.addQuery('city', current.city);
//grAst.addQuery('country', current.country);
grAst.addQuery('postcode', current.postcode);

grAst.setLimit(1);


grAst.query();


if (grAst.hasNext() && grAst.sys_id == current.sys_id)
{


gs.addErrorMessage("Serial number already exists");


current.setAbortAction(true);


}


})(current, previous);

 

Hi Kajal,

Is the table in the same scoped application

you can use abort action on the custom tables created as part of the scoped application(their own scope).

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

yes table is in same scoped application.

abort action is not woriking.