Hello,
I am trying to write a function which throws an error message if one of the records has a few field records which are duplicate.
Name of entity - dev_employee
Name of the lookup field - dev_centerid
Name of the field which needs to be checked for duplicates - dev_employeeid
So I am using SDk.Rest method to retrieve all the dev_employee records in which the dev_centerid is equal to the current record on which it will be run.
function EmployeeDuplicateDetection() {
var ecid = Xrm.Page.data.entity.attributes.get("dev_centerid").getValue()[0].id;
var EmpID = Xrm.Page.getAttribute("dev_employeeid").getValue();
var containsDuplicates = false;
SDK.REST.retrieveMultipleRecords(
"dev_employee",
"?$select=dev_employeeid,dev_entertainmentcenterid&$filter=dev_entertainmentcenterid/Id eq guid'" + ecid,
function (results) {
if (results.length > 0)
{
int length = results.length;
for(i=0; i<length; i++)
{
var employeeID = results[i].dev_employeeid;
if(employeeID == EmpID)
{
alert("Record with same Employee ID already exists. Please use different ID.");
}
}
}
},
function (error) {
alert(error.message);
},
function () {
//On Complete - Do Something
}
);
}
I am thrown a EmployeeDuplicateDetection() cannot be run on Event handler error. I have loaded the Rest.SDK library to the form as well.
*This post is locked for comments