Hello community experts,
I have a requirement where, if i try to enter a duplicate mail ID, that field should not allow me to enter the duplicate. I should throw an error, that this record already exist.
I tried using keys and duplicate detection rule.
Both does'nt meet this requirement.
Please Help.
Best Regards,
Sumaira Noor
Hi Sumaira,
Sorry for my mistake, in your case we should use "retrievemultiplereocrds" to get data because "retrieveRecord" could only get an special record with GUID.
So just use "retrievemultiplereocrds" instead, and which entity are you filling the emailaddress? According to your code, I think you might using contact. Then you need to replace the main entity "email" with "contact".
function compareEmailID(executionContext){
var formContext = executionContext.getFormContext();
var emailID=formContext.getAttribute("emailaddress1").getValue();
Xrm.WebApi.retrieveMultipleRecords("contact","?$select=emailaddress1&$filter=emailaddress1 eq '" + emailID+"'").then(
function success(result) {
if (result.length>0) {
Xrm.Page.ui.setFormNotification("This EmailID is exsited, please try another one!", "ERROR")
}
},
function error(error) {
Xrm.Navigation.openAlertDialog({ text: error.message });
}
);
}
docs.microsoft.com/.../retrievemultiplerecords
Hope it helps.
Best Regards,
Leo
Thanks for the response Leo.
Here is the code.
I have added it as a script webresource
function compareEmailID(executionContext){
var formContext = executionContext.getFormContext();
var emailID=formContext.getAttribute("emailaddress1").getValue();
Xrm.WebApi.retrieveRecord("email", "?$select=emailaddress1&$filter=emailaddress1 eq '" + emailID + "'").then(
function success(result) {
if (result.length>0) {
Xrm.Page.ui.setFormNotification("This EmailID is exsited, please try another one!", "ERROR")
}
},
function error(error) {
Xrm.Navigation.openAlertDialog({ text: error.message });
}
);
}
Hi Sumaira,
According to the error message, there should be something wrong in the web api filter conditions. Could you kindly share your code to us and so that we could debug or check it for you.
Best Regards,
Leo
Thanks for the response Leo
I'm attaching there screenshot below.
I have replaced the correct name
Best Regards,
Sumaira Noor
Hi partner,
Please pay attention that you should replace the correct field name in your case, "emialid" is only a sample.
If it is possible, please share the log file for more details.
Best Regards,
Leo
Thanks a lot for your response Leo
I'm getting this error
One of the scripts for this record has caused an error. For more details, download the log file.
Kindly guide
Best regards,
Sumaira Noor
Create a plugin and register it on create of respective entity.
In this plugin retrieve record that has same email id , If record found then throw invalid pluginexecution exception.
Hi partner,
First of all, we could not choose email as "base record type" in duplicate detection rule, so we could only use custom development.
If the mail ID is a custom field not GUID, there are 2 ways to meet your requirement.
1.Using JS code.
You could create a js function the compare the email ID you've entered in the create form with other existing emails and if this ID is existed, then throw an error or alert.
2.Using Plug-in.
You could refer to this doc with samples.
https://www.inogic.com/blog/2015/11/use-retrieveduplicaterequest-in-dynamics-crm/
Hope it helps.
Best Regards,
Leo
Thanks for the response Lu
Actually i tried many times the key feature is not working. It does'nt throw any error upon duplicate detection.
Best Regards,
Sumaira Noor
Hi Sumaira,
Could you tell me why the alternate key and duplicate detection rules don't meet your needs?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156