Using RetrievePrincipalAccessRequest in CRM


Hi,

Recently had a requirement to show\hide a ribbon button based on the condition i.e. if a user has Write access to that record show it else hide it.

Here either the user can have Write access to the record through the one of the security roles assigned to him or through the team which has that rights.

In this case we can use RetrievePrincipalAccessRequest which returns as response all the right user had on that particular record either through his own security roles or teams he is part of.

For e.g. we give following rights on a particular record to a team (which the user is part of)

If we check the rights user has on the record using RetrievePrincipalAccessRequest we get the following response (combination of all the rights either through sharing or his own security roles)

[


RetrievePrincipalAccessRequest request = new RetrievePrincipalAccessRequest();

// system user or team
request.Principal = new EntityReference("systemuser", new Guid("EBEECB5F-2D60-E511-80F8-3863BB357FC0"));

// record for which we want to check the access
request.Target = new EntityReference("is_productionsite", new Guid("15734DF9-31DD-E511-810E-3863BB353ED0"));

RetrievePrincipalAccessResponse resp = (RetrievePrincipalAccessResponse)orgService.Execute(request);

 

Hope it helps.

Get Total Count of records in CRM. (more than 5000)


For version 9.0 please check the below post

RetrieveTotalRecordCountRequest

https://dreamingincrm.com/2019/07/22/getting-entity-record-counts/

https://docs.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.retrievetotalrecordcountrequest?view=dynamics-general-ce-9

Just sharing a sample code to get the total number of records (e.g. account here)

 IOrganizationService orgService = GetOrganizationService();

 int totalCount = 0;

 QueryExpression query = new QueryExpression("account");
 query.ColumnSet = new ColumnSet();
 query.Distinct = true;
 query.ColumnSet.AddColumn("accountid");
 query.PageInfo = new PagingInfo();
 query.PageInfo.Count = 5000;
 query.PageInfo.PageNumber = 1;
 query.PageInfo.ReturnTotalRecordCount = true;

 EntityCollection entityCollection = orgService.RetrieveMultiple(query);
 totalCount = entityCollection.Entities.Count;

 while (entityCollection.MoreRecords)
 {
 query.PageInfo.PageNumber += 1;
 query.PageInfo.PagingCookie = entityCollection.PagingCookie;
 entityCollection = orgService.RetrieveMultiple(query);
 totalCount = totalCount + entityCollection.Entities.Count;
 } 

 MessageBox.Show(totalCount.ToString());

 

Hope it helps

Business Process Error while trying to open records in CRM 2015


Hi we were getting the below error while trying to open any record in CRM 2015

G

Turned out that by mistake one wrong extra step had got registered on RetrieveMultiple

ActivityFeeds.Plugins: ActivityFeeds.Plugins.ActivityClose]

[c824b80a-d392-e511-8114-3863bb356f90: ActivityFeeds.Plugins.ActivityClose: RetrieveMultiple of any Entity]

Removing this step fixed the issue.

Hope it helps.

Fixed – Microsoft Dynamics CRM Reporting Authoring Extension Setup – Setup cannot continue because there is a pending restart required error in CRM 2015


Hi,

Got the below error while trying to install the Report Authoring Extension for CRM 2015.

To fix the issue, open the log file, check for the registry path and delete it

Hope it helps !

Sample code to read XML Data from Web Resource in Plugin in CRM 2011/2013/2015


We recently had a requirement to read xml data stored in a particular web resource in plugin.

Sharing the sample code


public static Dictionary<string, string> GetMarketClusterAndMarketSegment(string webresourceName, string buildingTypeValue, IOrganizationService organizationService)
{
Dictionary<string, string> dictionaryMarket = new Dictionary<string, string>();

// tk_et_oppline_marketingfilterpicklists
// create request to retrieve Webresource
ColumnSet cols = new ColumnSet();
cols.AddColumn("content");
QueryByAttribute requestWebResource = new QueryByAttribute
{
EntityName = "webresource",
ColumnSet = cols
};
requestWebResource.Attributes.AddRange("name");
requestWebResource.Values.AddRange(webresourceName);

Entity webResourceEntity = null;
EntityCollection webResourceEntityCollection = organizationService.RetrieveMultiple(requestWebResource);

if (webResourceEntityCollection.Entities.Count > 0)
{
webResourceEntity = webResourceEntityCollection.Entities[0];
byte[] binary = Convert.FromBase64String(webResourceEntity.Attributes["content"].ToString());
string resourceContent = System.Text.Encoding.UTF8.GetString(binary);
string byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
if (resourceContent.StartsWith(byteOrderMarkUtf8))
{
resourceContent = resourceContent.Remove(0, byteOrderMarkUtf8.Length);
}

XDocument xmlDocument = XDocument.Parse(resourceContent);

var marketSegment = from t in xmlDocument.Descendants("ParentField").ElementAt(1).Descendants("ShowOption")
where t.Attribute("value").Value.Equals(buildingTypeValue)
select new
{
marketSegmentValue = t.Parent.Attribute("value").Value,
marketSegmentLabel = t.Parent.Attribute("label").Value
};

foreach (var v in marketSegment)
{
dictionaryMarket.Add("marketsegment", v.marketSegmentValue);
var marketCluster = from t in xmlDocument.Descendants("ParentField").ElementAt(0).Descendants("ShowOption")
where t.Attribute("value").Value.Equals(v.marketSegmentValue)
select new
{
marketClusterValue = t.Parent.Attribute("value").Value,
marketClusterLabel = t.Parent.Attribute("label").Value
};

foreach (var m in marketCluster)
{
dictionaryMarket.Add("marketcluster", m.marketClusterValue);
}
}
}

return dictionaryMarket;
}
}

Hope it helps..

Query execution time of 60 seconds exceeded the threshold of 10 seconds warning in CRM 2013.


Query execution time of 60 seconds exceeded the threshold of 10 seconds warning in CRM 2013.

We were getting the below warning in one of our test environment

On analyzing figured out that one of the plugin was using retrieve with ColumnSet(true) option i.e. retrieving all the columns of the entity which was not required in this case.

Fetching only the required columns fixed the warning.

The other option could have been indexing or increate the value for LongQueryThersholdInSeconds column in ServerSetingProperties table of MSCRM_Config.

Helpful posts

http://blog.edgewater.com/2013/01/07/microsoft-dynamics-crm-querying-data-using-late-binding-versus-early-binding/

http://www.dynamicscrmpros.com/mscrmplatform-warning-in-event-viewer-in-microsoft-dynamics-cr-event-id-17972/

Hope it helps..