Question

HI, Guys Adding contact with same data will not allow to add

I need your help on code level for adding new contact.

Example:- User can creating a contact with using same name or mobile number or email .It will not allow to save the contact it have to show one popup.

Like 0

Like

6 comments

Dear Praveen,

Such task can be achieved in two ways. The first one involves using deduplication rules on save. The second one requires developing skill for implementation.

If you do not feel strong with developing, please consider using deduplication rules. They will display you contacts, which have the same mobile phone or email before you save the contact. 

https://academy.bpmonline.com/documents/base/7-13/how-search-duplicates…

In case you decide to go for development, please see the steps needed to create such functionality:

1. Create the replacing client module for ContactPageV2 schema, in case you do not have one already.

2. Override the basic save() method. Firstly, retrieve the inserted name, mobile phone and email from the page (this.get("ColumnName")). Then run an ESQ function to the Contact object setting up the filters based on the retrieved name, mobile phone and email. Instructions on creating ESQ function you can find here:

https://academy.bpmonline.com/documents/technic-sdk/7-13/use-entitysche…

In case the responding collection will be empty, you can proceed further with save method, so you call its parent realization. If collection is not empty you can show a modal window to the user (this.showInformationDialog("Some text");

Please draw your attention, that ESQ is an asynchronous function.

Hope you will find it helpful.

Regards,

Anastasia

can you please post the code 

praveen n,

Unfortunately, we do not have the ready code snippet for this case. However, we have provided with the steps and algorithm for your task.

Please check the provided links and in case you will have difficulties along the implementation, please provide us with the debugging results and code written. We will be happy to help.

Anastasia

Anastasia Botezat

I was written some code for Adding contact with same data will not allow to add for mobile phone and email but here what happening is when you are filling the new contact form. If data is matching it is showing pop up like(already exists)for both mobile phone and email but after clicking OK on popup if you click  on save button it is saving.

here the code:

 

define("ContactMiniPage", [], function() {

    return {

        // Edit page object schema name.

        entitySchemaName: "Contact",

        details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,

        // The attributes property of the view model.

        attributes: {

            "Email": {

                dataValueType: Terrasoft.DataValueType.TEXT,

                dependencies: [

                    {

                        columns: ["Email"],

                        methodName: "validateEmail"

                    }

                ]

            },

            "MobilePhone": {

                // Data type of the view model column.

                dataValueType: Terrasoft.DataValueType.TEXT,

                // Array of configuration objects that determines [UsrBalance] column dependencies.

                dependencies: [

                    {

                        // The value in the [UsrBalance] column depends on the [Amount] 

                        // and [PaymentAmount] columns.

                        columns: ["MobilePhone"],

                        // Handler method, which is called on modifying the value of the on of the columns: [Amount] 

                        // and [PaymentAmount].

                        methodName: "getmobilenumber"

                    }

                ]

            }

        },    

        // Collection of the edit page view model methods.

        methods: {

            getmobilenumber: function() {

                    var recordMobilePhone = this.get("MobilePhone");

                    var message = "";

                    var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", {

                        rootSchemaName: "Contact"

                    });

                    

                    esq.addColumn("Name", "Name");

                    esq.addColumn("MobilePhone", "MobilePhone");

                    

                    var esqPhoneFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, 

                                                "MobilePhone", recordMobilePhone);

                                                

                    esq.filters.add("esqFirstFilter", esqPhoneFilter);

                    

                    esq.getEntityCollection(function (result) {

                        if (!result.success) {

                            this.showInformationDialog("Data query error");

                            return false;

                        }

                        else{

                            result.collection.each(function (item) {

                                message += "Mobile Phone: " + item.get("MobilePhone") + " already exists for "

                                    + item.get("Name") ;

                                this.showInformationDialog(message);

                                return false;

                            });

                        }

                        

                    }, this);

            },

            validateEmail: function() {

                var recordEmail = this.get("Email");

                    var message = "";

                    var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", {

                        rootSchemaName: "Contact"

                    });

                    

                    esq.addColumn("Name", "Name");

                    esq.addColumn("Email", "Email");

                    

                    var esqEmailFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, 

                                                "Email", recordEmail);

                                                

                    esq.filters.add("esqFirstFilter", esqEmailFilter);

                    

                    esq.getEntityCollection(function (result) {

                        if (!result.success) {

                            this.showInformationDialog("Data query error");

                            return false;

                        }

                        else{

                            result.collection.each(function (item) {

                                message += "Email " + item.get("Email") + " already exists for "

                                    + item.get("Name") ;

                                this.showInformationDialog(message);

                                return false;

                            });

                        }

                        

                    }, this);

            }

        },

        // Visual display of the [UsrBalance] column on the edit page.

        diff: /**SCHEMA_DIFF*/[

            {

                "operation": "insert",

                "parentName": "MiniPage",

                "propertyName": "items",

                "name": "Email",

                "values": {

                    "visible": {"bindTo": "isNotViewMode"},

                    "isMiniPageModelItem": true,

                    "layout": {

                        "column": 0,

                        "row": 7,

                        "colSpan": 24

                    }

                }

                },

                {

                "operation": "insert",

                "parentName": "MiniPage",

                "propertyName": "items",

                "name": "MobilePhone",

                "values": {

                    "className": "Terrasoft.PhoneEdit",

                    "visible": {"bindTo": "isNotViewMode"},

                    "isMiniPageModelItem": true,

                    "layout": {

                        "column": 0,

                        "row": 6,

                        "colSpan": 24

                    }

                }

            }

        ] /**SCHEMA_DIFF*/

};

}

);

Anastasia Botezat,

Actually, I have developed code for validation but it is executing onblur of corresponding field. Instead, I want to run my validation code on click of Save button in new Contact form. 

Can you please suggest me where can I do this mapping. Thanks much in advance.

praveen n,

You need to override the save method for your custom logic to work when saving. For instance, in the code snippet below I have overriden the save method where I added if clause. It is checking whether my conditions match. If validation does not return any already existing same emails and numbers only  in that case I process with the parent realization, which saves the record. 

			save: function() {
				var message = "";
				var email = this.get("EmailExists");
				var mobile = this.get("MobileExists");
				if(email) {
					message += "Email  already exists";
					this.showInformationDialog(message);
				} else if (mobile) {
					message += "Mobile Phone: already exists";
					this.showInformationDialog(message);
				} else {
					this.callParent(arguments);
				}
			}

 Please notice, that I am retrieving   var email = this.get("EmailExists");

        and        var mobile = this.get("MobileExists");  These are the virtual attributes, which I declared for results of my ESQ. In case there are any records received I set the attribute value to true, which I can use in save method:

			"MobileExists": {
				dataValueType: Terrasoft.DataValueType.BOOLEAN,
				type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
				value: false
			},
			"EmailExists": {
				dataValueType: Terrasoft.DataValueType.BOOLEAN,
				type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
				value: false
			},

You can use this, or any other approach, however, the main idea s to override the save method.

Regards,

Anastasia

Show all comments