web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Dynamics CRM 2011 View to display records shared with current user

Zhongchen Zhou Profile Picture Zhongchen Zhou 681

In my current project, there is a requirement to create a view to display shared record of certain entity.

This kind of view is supported but can not be achieved through customization user interface.

System view and user view are defined by using fetchxml and layoutxml, we could create a view through CRM API and set the correct fetchxml with is not support in out of the box customization user interface.

When records are shared, CRM create a record of “principalobjectaccess” entity; so we can link the entity we want to display to this entity to construct proper fetchxml.

The drawback of the approach is that you can not use customization user interface to modify the column layout and sort order.

Suppose we have an entity called “zzhou_cfiapplication” and we want to create a view to display records shared with current user.

The important piece of xml to add to view fetchxml is the link entity to “principalobjectaccesss” entity.


<link-entity name='principalobjectaccess' to='zzhou_cfiapplicationid' from='objectid' link-type='inner' alias='share'>
 <filter type='and'>
 <condition attribute='principalid' operator='eq-userid' />
 </filter>
</link-entity>

It is much more easier to configure the view in customization user interface to set up correct columns and sort order, and then modify the fetchxml for that view.

We can use the following code to retrieve the view that we want to modify


public Entity RetrieveSavedQuery(OrganizationServiceContext context, Guid queryId)
 {
 var query = from q in context.CreateQuery("savedquery")
 where q.GetAttributeValue<Guid>("savedqueryid") == queryId
 select q;

Entity record = query.FirstOrDefault();

return record;
 }

we can update the view by using the following code

</pre>
public void UpdateSavedQuery(IOrganizationService service)
 {
 Entity savedQuery = new Entity("savedquery");
 savedQuery.Id = new Guid("00bc926f-26c0-e111-a4f9-00155d4c5b01");
 savedQuery["fetchxml"] = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
 <entity name='zzhou_cfiapplication'>
 <attribute name='zzhou_name' />
 <attribute name='createdon' />
 <order attribute='zzhou_name' descending='false' />
 <link-entity name='principalobjectaccess' to='zzhou_cfiapplicationid' from='objectid' link-type='inner' alias='share'>
 <filter type='and'>
 <condition attribute='principalid' operator='eq-userid' />
 </filter>
 </link-entity>
 <attribute name='zzhou_cfiapplicationid' />
 </entity>
 </fetch>";

service.Update(savedQuery);
 }
<pre>

This was originally posted here.

Comments

*This post is locked for comments