Users cannot create duplicate contacts with same name, email or mobile number.
Hi,
Team
In contact section if you are creating the new contact with same mobile number or email it have to show one popup like email or mobile number is already exists and does not allow you to save contact while clicking on save. Here the pop up is showing while saving the record.The problem is if you add new contact with different credentials save button is not working.
Can anyone help on this issue Here the code which i was written.
define("ContactMiniPage", [], function() {
return {
entitySchemaName: "Contact",
details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
/* attributes: {
"Email": {
dataValueType: Terrasoft.DataValueType.TEXT,
dependencies: [
{
columns: ["Email"],
methodName: "validateEmail"
}
]
},
"MobilePhone": {
dataValueType: Terrasoft.DataValueType.TEXT,
dependencies: [
{
columns: ["MobilePhone"],
methodName: "validateMobileNumber"
}
]
}
},*/
methods: {
validateForm: function() {
var recordMobilePhone = this.get("MobilePhone");
var recordEmail = this.get("Email");
var message = "";
//Validate when phone is not nul or empty
if(recordMobilePhone !== null && recordMobilePhone !== "" && recordMobilePhone !== undefined)
{
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 = message + "Mobile Phone " + item.get("MobilePhone") + " already exists for "
+ item.get("Name") +"\n";
// this.showInformationDialog(message);
// return false;
});
}
if(message !== "" && (recordEmail === null || recordEmail === "" || recordEmail === undefined)){
this.showInformationDialog(message);
}
}, this);
}
//Validate when email is not nul or empty
if(recordEmail !== null && recordEmail !== "" && recordEmail !== undefined)
{
// var emailMessage = "";
var emailesq = this.Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "Contact"
});
emailesq.addColumn("Name", "Name");
emailesq.addColumn("Email", "Email");
var esqEmailFilter = emailesq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
"Email", recordEmail);
emailesq.filters.add("esqFirstFilter", esqEmailFilter);
emailesq.getEntityCollection(function (result) {
if (!result.success) {
this.showInformationDialog("Data query error");
return false;
}
else{
result.collection.each(function (item) {
message = message + "Email " + item.get("Email") + " already exists for "
+ item.get("Name")+"\n";
// return false;
});
}
if(message !== ""){
this.showInformationDialog(message);
}
}, this);
}
}
},
diff: /**SCHEMA_DIFF*/[
{
"operation": "merge",
"name": "SaveEditButton",
"parentName": "MiniPage",
"propertyName": "items",
"values": {
"itemType": Terrasoft.ViewItemType.BUTTON,
"click": {"bindTo": "validateForm"}
}
}
] /**SCHEMA_DIFF*/
};
}
);
Like
Hello,
The reason of the issue that you are facing with is that "click" property of button is binded to "validateForm" method, instead of "save".
If I understood you right, the task is to validate form before saving, so you should simply call "validateForm" method before saving.
So, to achieve the task you should override save method. In that method "validateForm" method should be triggered.
Please note, that to be confident that base logic will work correctly the this.callParent(arguments) method should be triggered too.
Best regards,
Alex