How to fetch Users with Security roles using fetch xml


<fetch mapping=”logical” count=”50″ version=”1.0″ >
<entity name=”systemuser” >
<attribute name=”fullname” />
<link-entity name=”systemuserroles” from=”systemuserid” to=”systemuserid” >
<link-entity name=”role” from=”roleid” to=”roleid” >
<attribute name=”name” />
<attribute name=”roleid” />

——————————Below fetch can be used in fetch based report———-

<fetch mapping=”logical”>
<entity name=”systemuser” >
<attribute name=”fullname” />
<attribute name=”systemuserid” />
<link-entity name=”systemuserroles” from=”systemuserid” to=”systemuserid” alias=”systemMapping” >
<link-entity name=”role” from=”roleid” to=”roleid” alias=”RoleTable” >
<attribute name=”name” />
<attribute name=”roleid” />



Below i have attached the document link in this i have put every image and comments to resolve the subjected error.

Associate Entity Type code wrong mapping solution
















Question may occur in your mind that from where you will get the correct “entity object type code” ?

For that you can use “XRM Tool Box metadata browser option.

Happy Learning… 🙂

If you like this post please follow…



Javascript calls action in CRM

//this function is responsible to set the headers

var setRequestHeaders = function (req, includeFormattedValues, customHeaders) {
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”);
if (!(includeFormattedValues !== undefined && includeFormattedValues !== null && includeFormattedValues === false)) {
req.setRequestHeader(“Prefer”, “odata.include-annotations=\”OData.Community.Display.V1.FormattedValue\””);

if (!(customHeaders && customHeaders.constructor === [].constructor)) {
customHeaders = [];
customHeaders.forEach(function (h) {
switch (h.key) {
case “Accept”:
case “Content-Type”:
case “OData-MaxVersion”:
case “OData-Version”:
case “Prefer”:
req.setRequestHeader(h.key, h.value);


// function name
stringParameterCheck = function (parameter, message) {
if (typeof parameter !== “string”) {
throw new Error(message);

//Async function

executeCustomAction = function (entityId, entityCollectionName, actionName, parameters, isGlobleAction, successCallback, errorCallback, customHeaders) {
var query = “”, req = “”;
stringParameterCheck(actionName, “MisXrmUtilities.WebAPI.executeCustomAction requires the actionName parameter is a string.”);

if (isGlobleAction !== undefined && isGlobleAction !== null && isGlobleAction !== true) {
stringParameterCheck(entityId, “MisXrmUtilities.WebAPI.executeCustomAction requires the e entityId parameter is a string.”);
stringParameterCheck(entityCollectionName, “MisXrmUtilities.WebAPI.executeCustomAction requires the entityCollectionName parameter is a string.”);
entityId = entityId.replace(“{“, “”).replace(“}”, “”);
query = entityCollectionName + “(” + entityId + “)/Microsoft.Dynamics.CRM.” + actionName;
else {
query = actionName;

req = new XMLHttpRequest();“POST”, getWebAPIPath() + query, true);
setRequestHeaders(req, false, customHeaders);
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
switch (this.status) {
case 200:
case 204:
case 1223:


req.send((parameters !== undefined && parameters !== null) ? JSON.stringify(parameters) : null);

//==============How to use this function==================//
parametersInJsonFormate = {
ActionInputParameter1: “here is the input”, // Make sure the name maches with the action input parameters
ActionInputParameter2: “anything can be passed”
executeCustomAction(entityId, entityCollectionName, actionName, parametersInJsonFormate, false, function(success){
//Success call back
}, function(error){

//Error call back

Request message has unresolved parameters.

In CRM when you get this error while calling action. then there may be three reasons behind that

  1. some parameters you are passing wrong. (make sure action name is correctly pass)
  2. your action is not activated
  3. your action name is duplicate and one action is in active mode and other is in draft.(as this is done from CRM side that one has to be in draft only two same name action wont be active at same time.)
  4. When we use assign value step then if the step wants to return some value then we need to create one output parameter or it might give error.


I will talk about the 3) point. here.

to resolve this you need to delete the draft or other active actions, keep only one.

I have seen by default it will create two action in active mode. that’s fine let it  be

if it gives error while deleting your action then deactivate all the actions which we search on advance fine and then delete all and recreate.

How will you find it ???

Go to advance find and delete the default filters and put you process name contains (your action name) and you will find out there are actually two action with the same name.

How this happened in CRM???

🙂 you may have imported the actions twice in CRM.

A system restart from a previous installation or update is pending, and that setup cannot continue

  1. Open the Windows Registry Editor:
    • Windows XP: Click StartRun, type regedit and then click OK.
    • Windows Vista / 7: Click Start, type regedit in the Search field and then press Enter.
    • Windows 8: Press the Windows Key + R on your keyboard, type regedit and then click OK.
  2. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\.
  3. Find RunOnce registry key under currentVersion folder and Delete That
  4. Do the same thing with the HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\.

delete RunOnce folder in current version folder  from here too.

Then you don’t need to restart your system again and again.



Fetch XML for getting access “Assign position for User” privilege

This Fetch XML gives “Assign position for User” access privilege  for the current logged in user roles.


<entity name=”roleprivileges” >
<link-entity name=”role” from=”roleid” to=”roleid” link-type=”inner” alias=”Role” >
<attribute name=”name” />
<link-entity name=”systemuserroles” from=”roleid” to=”roleid” link-type=”inner” >
<link-entity name=”systemuser” from=”systemuserid” to=”systemuserid” link-type=”inner” >
<condition attribute=”systemuserid” operator=”eq-userid” />
<link-entity name=”privilege” from=”privilegeid” to=”privilegeid” link-type=”inner” alias=”Privilege” >
<attribute name=”canbebasic” />
<attribute name=”canbedeep” />
<attribute name=”accessright” />
<attribute name=”canbelocal” />
<attribute name=”canbeglobal” />
<attribute name=”canbeentityreference” />
<attribute name=”canbeparententityreference” />
<attribute name=”name” />
<condition attribute=”name” operator=”eq” value=”prvAssignPosition” />

CA2227 Collection property should be readonly

TypeName: CollectionPropertiesShouldBeReadOnly
CheckId: CA2227
Category: Microsoft.Usage
Message Level: Warning
Certainty: 75%
Breaking Change: Breaking

Cause: An externally visible writable property is a type that implements System.Collections.ICollection. Arrays, indexers (properties with the name ‘Item’), and permission sets are ignored by the rule.

Solution for this is as follows: 

public IList<Account> Account{ get; private set; }

Then we need to use this property in the same class, In derived class this property can be accessible(get). but set will be in the same class only.

Now if we want to set this property from other class then we can create one method in the class where we can use this property for setting purpose.

 this.Account = new List<Account>();

this.Account.Add("Here Add you account object");