Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

Unable to get existing organization wide lead count

$
0
0

Hi,

We are using a JavaScript function on form field onchange event to detect the duplicate entries in the entity and alerting the users.

This script works perfectly but considering only records based on role. If admin user checks in the entire organization records whereas specific BU user checks the records only specific to the BU.

Problem is the if lead record is already available in other BU cant be notified to the BU users as the role restricts the records to specific BU. Anyway to override without compromising on the security roles?

My script is :

function CaptureDuplicates_email_onchange(eventArgs) {

var email = Xrm.Page.getAttribute("emailaddress1");
var isNull = email.getValue() == null;
var isBlank = email.getValue() == "";
var notificationMessage = "Error";

if (isNull || isBlank) {
Xrm.Page.ui.setFormNotification("To save this record, please enter either an Email address, Main Phone or Mobile number.", "ERROR", notificationMessage);
eventArgs.returnValue = false;
}
else {
Xrm.Page.ui.clearFormNotification(notificationMessage);
}

if (email.getValue() != null) {
var emailvalue = Xrm.Page.getAttribute("emailaddress1").getValue();
var context = Xrm.Page.context;
var serverUrl = context.getClientUrl();
var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var retrieveResult = new XMLHttpRequest();

retrieveResult.open("GET", ODataPath + "/LeadSet?$select=FullName&$filter=(EMailAddress1 eq '" + emailvalue + "')", false);
retrieveResult.setRequestHeader("Accept", "application/json");
retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8?");
retrieveResult.send();
if (retrieveResult.readyState == 4 /* complete */) {
if (retrieveResult.status == 200) {
var retrieved = this.parent.JSON.parse(retrieveResult.responseText).d;
var Result = retrieved.results;
if (typeof Result !== "undefined") {
var count = Result.length;
if (count > 0) {
Xrm.Page.ui.setFormNotification("Duplicates found. Please enter a unique value for email.", "ERROR", notificationMessage);
alert("Duplicates found. Please enter a unique value for email");
email.setValue(null);
Xrm.Page.getControl("emailaddress1").setFocus();

}
}
}
}
}
}


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>