Hi @Shubhk
Here is the Javascript code to check entry exists or not
The below check the account number that exists on the Account entity.
Setup:
- Create new web resource for Javascript say Account.js
- Copy the below code and update the above new file
- Call the "verifyAccountNumber" method from onchange event of Account Number
function verifyAccountNumber(executionContext) {
var formContext = executionContext.getFormContext();
var accountNumber = formContext.getAttribute("accountnumber").getValue();
var uniqueId="028d0060-bb07-4d9e-ab2e-080a18f1e8ec";
try {
var query = "accounts?$select=name,accountnumber&$filter=(accountnumber eq '" + accountNumber + "')";
//Create a request
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/" + query, false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.send();
if(req.readyState == 4)
{
//Success
if (req.status == 200) {
var results = JSON.parse(req.response);
var recordCount = results.value.length;
if (recordCount > 0) {
alert("Account Number Already Exists");
formContext.ui.setFormNotification('Account Number Already Exists', 'WARNING', uniqueId);
}
}
//Failure
else {
alert("Error: " + req.responseText);
}
}
} catch (e) {
Xrm.Utility.alertDialog(e);
}
}
Call the method
- Add the reference file that you created above
- Set the function name

2 Outputs
1. Regular Alert

2. Form Notification

Thanks,
Stalin - Learn To Illuminate