Run Duplicate check on keyup event of backbone

Hi All,

I am using a SugarCRM 7.7.0.0. 

I want to run the default duplicate check functionality of SugarCRM on keyup event of the backbone controller. 

So far, I have written the following code to extend the default controller of the record view, and I am unable to find what to do next (how to run the duplication check). 

following file is located at: 

custom/modules/Contacts/clients/base/views/record/record.js

({
extendsFrom:'RecordView',

initialize: function(options){
this._super('initialize', [options]);

//Add event that listens for keup event on last_name field
this.events['keyup input[name=last_name]'] = 'checkDuplicates';
},

checkDuplicates: function(){
//Get current value of last_name
var sLast = this.model.get('last_name');

//Check for duplicate vlues if not empty
if (!_.isEmpty(sLast))
{
// run the default duplicate check for the contacts module here.
}
},
})

Any help will be appreciated. 

  • There should be a  POST endpoint for duplicate check with the URL /<module>/duplicateCheck with a record field (e.g. { "name":"Airline" }).

    You could either use ajax:

    $.ajax({
                beforeSend: function (request)
                {
                    request.setRequestHeader("OAuth-Token", SUGAR.App.api.getOAuthToken());
                },
                url: "rest/v10/<YourModule>/duplicateCheck",
                data: {"name":"Airline"},
                dataType: "json",
                type: "POST",
                success: function(data){
                     //the data would have what you want here
                }
        });

    Alternatively using Sugar's inbuilt tools:

     App.api.call('create', App.api.buildURL('<module>', 'duplicateCheck'), {"name":"Airline"}, {
                success: function (data) {
                    //duplicates are in data here
                },
                error: function (e) {
                }
            });

    I haven't tested these snippets, but you should be able to look at the api yourself at <yoursugarurl>/rest/v10/help.

    Hope this helps!

  • Hi Alan,

    Thanks for the time to respond to the question. I have used this snippet and it works fine. 

    I am looking for a way to run the duplicate check in the way that it finds duplicates, and if found, it should display all of them on top of the screes as it does while clicking on "Save button".