duplicate checking for multiple fields using business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2020 01:17 AM
Here i want to avoid duplicate values for six fields using business rule and applied this code .Here for one field it is working correctly but for two or more than that it is not working. It simply takes the values in table and also showing" invalid insert message" it shows this message and also gets inserted in the table
Here is the code that i applied
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var grAst = new GlideRecord('tablename');
grAst.addQuery('name', current.name);
grAst.addQuery('roll', current.roll);
grAst.addQuery('address', current.address);
grAst.addQuery('city', current.city);
grAst.addQuery('school', current.school);
grAst.addQuery('pincode', current.pincode);
grAst.setLimit(1);
grAst.query();
if (grAst.hasNext() && grAst.sys_id != current.sys_id)
{
gs.addErrorMessage("Serial number already exists");
current.setAbortAction(true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 06:20 AM
Are you looking to ensure that the record has unique values for all six fields or that all six fields have unique values?
Example 1:
RecA: name=chuck.tomasi, id=12345, dev=ffda
RecB: name=tom.smith, id=12345, dev=3dee
In your requirement, am I allowed to save recB if recA already exists or are these mutually exclusive?
Your script suggests that I can save B. If your requirement is that it should not be saved because the IDs are the same, then I recommend setting the dictionary field "unique=true" on each of the six fields you want to ensure uniqueness.