How to Get the List of Users Inside an Access Team

Many of you have probably tried to use the Access Teams feature of Dynamics 365 Customer Engagement (D365CE) to provide special access for specific records but one of the rather odd requirements that was asked of our project recently was to query the list of Access Team users on an Account Record and Pre-Filter the Owner field to limit the Lookup only to the specific users in the Access Team list.  Pre-Filtering is nothing new in D365CE so I went ahead and added a Pre-Filter that would probably look like something like this:

var filter = Some Fetch XML Filter
Ownercontrol.addPreSearch(function () {
  Ownercontrol.addCustomFilter(filter);
});

I went ahead and opened Advanced Find and to my surprise I didn’t find any Entity named Access Team or some name that was connected to Access Team. I opened the Users Entity to search and to my dismay I didn’t find a single field that pointed to Access Team or Account where the Access Team was enabled. So I went and searched the fields in Account and saw a field named preferredsystemuserid. I thought, this is it! But when I tried to query a value using XrmToolBox’s FetchXML Builder by Jonas Rapp of Innofactor Sweden, I was disappointed to find out that the field wasn’t even displayed on the results view.

So I tried so search until I noticed a reference to some entity called the principalobjectaccess and found that this entity is quite useful in help us out of our problem.

The results of this Fetch XML statement will return a list of System User Guids which I can now use to populate my Pre-Filter query.  I passed this Fetch XML query through D365CI’s Web API and got the results. If you want to know how to pass Fetch XML using the Web API you can read about it HERE or you can use Jason Lattimer’s CRM Rest Builder to do the heavy lifting for you. After you have retrieved the results you can pass the results to the data parameter and create the Pre-Filter as follows:

filter = "";
filter += "";
var index = 0;
for (index = 0; index < data.value.length; index++) {
    filter += "" + data.value[index].user_x002e_systemuserid + "";
}
filter += "";
Ownercontrol.addPreSearch(function () {
 Ownercontrol.addCustomFilter(filter);
});

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s