We have recently migrated from CRM 2011 RU 8 to RU 18. I am trying to retrieve a custom entity records by SOAP call. Its working fine with the user who belongs to root Business Unit and having System Administrator role. But the same code is not working for any other users who belongs to any of the BUs with any roles(even for System Administrator) its giving error: Principal user (Id=GUID, type = 8) is missing prvRead[entity name] privilege (Id=GUID)
Need help if you have any idea on this issue.
SOAP Code:
RetrieveMultiple = function(entity, attribute, condition)
{
// Usage => RetrieveMultiple("new_entityname", "new_attribute1|new_attribute2|new_attribute3", "new_attribute1||value1||new_attribute2|Like|value2||new_attribute|NotNull";
// Refer to the following link for more operators >> http://msdn.microsoft.com/en-us/library/bb959309.aspx
// Prepare variables to retrieve the records.
var attributes = attribute.split('|');
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
authenticationHeader +
"<soap:Body>" +
"<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'" +
" xsi:type='q1:QueryExpression'>" +
"<q1:EntityName>" + entity + "</q1:EntityName>" +
"<q1:ColumnSet xsi:type='q1:ColumnSet'>" +
"<q1:Attributes>";
for (i = 0; i < attributes.length; i++)
xml += "<q1:Attribute>" + attributes[i] + "</q1:Attribute>"
xml +=
"</q1:Attributes>" +
"</q1:ColumnSet>" +
"<q1:Distinct>false</q1:Distinct>" +
"<q1:Criteria>" +
"<q1:FilterOperator>And</q1:FilterOperator>" +
"<q1:Conditions>";
var conditionDetails;
var conditions = condition.split('||');
for (i = 0; i < conditions.length; i++) {
conditionDetails = conditions[i].split('|');
xml +=
"<q1:Condition>" +
"<q1:AttributeName>" + conditionDetails[0] + "</q1:AttributeName>" +
"<q1:Operator>" + conditionDetails[1] + "</q1:Operator>";
if (conditionDetails.length > 2) {
xml +=
"<q1:Values>" +
"<q1:Value xsi:type='xsd:string'>" + conditionDetails[2] + "</q1:Value>" +
"</q1:Values>";
}
xml +=
"</q1:Condition>";
}
xml +=
"</q1:Conditions>" +
"</q1:Criteria>" +
"</query>" +
"</RetrieveMultiple>" +
"</soap:Body>" +
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0) {
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
//alert(msg);
return msg;
}
// Parse and display the results.
else {
var results = resultXml.getElementsByTagName('BusinessEntity');
var msg = "";
if (results.length == 0) {
//msg = "No record found with the given criteria.";
//alert(msg);
//return;
return null;
}
else {
var result = "";
for (i = 0; i < results.length; i++) {
if (i != 0)
result += '|';
for (j = 0; j < attributes.length; j++) {
if (i != 0 || j != 0)
result += '|';
if (results[i].selectSingleNode('./q1:' + attributes[j]) != null)
result += results[i].selectSingleNode('./q1:' + attributes[j]).nodeTypedValue;
}
}
return result;
}
}
}