Hi Andrew, thanks for your response.
is there an alternate query data you can suggest to validate active account names do not contain word with similar strings.
for example:
Account 1 Name: Microsoft Azure
Account 2 Name: MicrosoftAzure
This be identified as a potential duplicate.
I found an alternate way but this first stores all the active accounts and then check from the array, which is not at all efficient.
function checkForDuplicateAccountNames(executionContext) {
var formContext = executionContext.getFormContext();
var accountName = formContext.getAttribute("name").getValue().replace(/\s+/g, '');
var accounts = [];
var query = "?$select=name,statecode&$filter=statecode eq 0";
executionContext.getEventArgs().preventDefault();
Xrm.WebApi.retrieveMultipleRecords("account", query).then(
function success(result) {
accounts = result.entities;
var filteredAccounts = accounts.filter(function (account) {
return account.name.replace(/\s+/g, '') === accountName;
});
if (filteredAccounts.length > 0) {
var confirmStrings = { text: "An account with this name already exists. Do you still want to create/update it?" };
var confirmOptions = { height: 200, width: 450 };
Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
function (success) {
// If the user clicks Yes, allow the form to save
if (success.confirmed) {
isValidationNeeded = false;
formContext.data.entity.save();
}
},
function (error) {
console.log(error.message);
}
);
}
else {
isValidationNeeded = false;
formContext.data.entity.save();
}
},
function error(error) {
console.log(error.message);
}
);
}