Duplicate Record check

Jaya9
Tera Contributor

Hi , 

 

I have created a custom table for banking account details and then i have created a record producer for the same table that collect information for banking account  .

I have few fields on the form as user name , account number , address , phone no etc ... 

i need to add a duplicate check i.e when i fill the form i.e record producer with details like acc no , address , user name etc and submit it .. It should create a record in banking account details table and check in backend custom table if there is any record for same user or account .. the submitted request state should change to cancel .

 

Could you please help me with duplicate check part script .

Thanks in advance .

 

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

HI @Jaya9 ,
I trust you are doing great.
Here's an example script you can adapt:

(function() {
    var gr = new GlideRecord('your_custom_table'); // Replace 'your_custom_table' with the actual name of your custom table
    gr.addQuery('account_number', current.account_number); // Replace 'account_number' with the field name of account number in your table
    gr.addQuery('user_name', current.user_name); // Replace 'user_name' with the field name of user name in your table
    gr.query();

    if (gr.next()) {
        // Duplicate found, set the state to 'Cancelled'
        current.state = 'Cancelled'; // Replace 'state' and 'Cancelled' with the actual field name and value for your cancelled state
        current.update();
        gs.addInfoMessage('A record with the same account number and user name already exists. This request has been cancelled.');
    } else {
        // No duplicate found, proceed with record creation
        // The record will be created automatically after this script runs
    }
})();

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

2 REPLIES 2

Elijah Aromola
Mega Sage

Below is a generic script that would need to be modified for the correct table/fields. You should be able to use this script in a before business rule on the table that the record producer is on. If a duplicate is found, it will set the new record to cancelled.

var duplicateGlideRecordCheck = new GlideRecord("table_name_to_check");
duplicateGlideRecordCheck.addQuery("account", current.account); // create as many addQuery methods as you need for each field you have to check
duplicateGlideRecordCheck.query();
if(duplicateGlideRecordCheck.hasNext()) {
    current.state = 'cancelled_state_value';
}

 

Amit Gujarathi
Giga Sage
Giga Sage

HI @Jaya9 ,
I trust you are doing great.
Here's an example script you can adapt:

(function() {
    var gr = new GlideRecord('your_custom_table'); // Replace 'your_custom_table' with the actual name of your custom table
    gr.addQuery('account_number', current.account_number); // Replace 'account_number' with the field name of account number in your table
    gr.addQuery('user_name', current.user_name); // Replace 'user_name' with the field name of user name in your table
    gr.query();

    if (gr.next()) {
        // Duplicate found, set the state to 'Cancelled'
        current.state = 'Cancelled'; // Replace 'state' and 'Cancelled' with the actual field name and value for your cancelled state
        current.update();
        gs.addInfoMessage('A record with the same account number and user name already exists. This request has been cancelled.');
    } else {
        // No duplicate found, proceed with record creation
        // The record will be created automatically after this script runs
    }
})();

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi