How to Block Duplicate Record?

RobsonG10844545
Giga Contributor

How to block the creation of a record through the record producer if the user has already made a request for the same record (course) and on the same date

2 ACCEPTED SOLUTIONS

Rafael Batistot
Kilo Patron

Hi @RobsonG10844545 

 

The best way is create a Business Rule > before > insert 

 

See an example of code 

 

var dup = new GlideRecord('u_course_registration');

    dup.addQuery('u_requested_for', current.u_requested_for);

    dup.addQuery('u_course', current.u_course);

    dup.addQuery('u_date', current.u_date);

    dup.query();

 

    if (dup.next()) {

        gs.addErrorMessage('You have already requested this course on this date.');

        current.setAbortAction(true); // If true,  will be aborted the record producer creation 

    }

 

This is an example, kindly send the names of fields from the form to give an code more correct 

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

View solution in original post

kaushal_snow
Giga Sage

@RobsonG10844545 ,

 

By writing a Before Business Rule on the target table that queries for an existing record matching the user, course and date, and if found aborts the insert (for example by using current.setAbortAction(true) or setting an error) so the duplicate is prevented....try this out..

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

View solution in original post

2 REPLIES 2

Rafael Batistot
Kilo Patron

Hi @RobsonG10844545 

 

The best way is create a Business Rule > before > insert 

 

See an example of code 

 

var dup = new GlideRecord('u_course_registration');

    dup.addQuery('u_requested_for', current.u_requested_for);

    dup.addQuery('u_course', current.u_course);

    dup.addQuery('u_date', current.u_date);

    dup.query();

 

    if (dup.next()) {

        gs.addErrorMessage('You have already requested this course on this date.');

        current.setAbortAction(true); // If true,  will be aborted the record producer creation 

    }

 

This is an example, kindly send the names of fields from the form to give an code more correct 

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

kaushal_snow
Giga Sage

@RobsonG10844545 ,

 

By writing a Before Business Rule on the target table that queries for an existing record matching the user, course and date, and if found aborts the insert (for example by using current.setAbortAction(true) or setting an error) so the duplicate is prevented....try this out..

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/