<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 - Discussions by asharsyed</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/asharsyed/Discussions/RSS"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 - Discussions by asharsyed</title>
		<link>http://channel9.msdn.com/Niners/asharsyed/Discussions</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Niners/asharsyed/Discussions</link>
	<language>en</language>
	<pubDate>Thu, 23 May 2013 02:33:59 GMT</pubDate>
	<lastBuildDate>Thu, 23 May 2013 02:33:59 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>0</c9:totalResults>
	<c9:pageCount>0</c9:pageCount>
	<c9:pageSize>0</c9:pageSize>
	<item>
		<title>Tech Off - Retrieving user privileges on entity using CRM 2011 SDK</title>
		<description><![CDATA[<p><span><span><span>Hi all,</span></span></span></p><p><span><span><span><span><span>I was using <span><span>RetrievePrincipalAccessRequest and </span><span>RetrievePrincipalAccessResponse objects to retreive user access rights on entity using entity instances. This worked until thus far when I tried to retreive access rights on custom entity.</span> </span></span></span></span></span></span></p><p><span><span><span>I get the following error &quot;The 'RetrievePrincipalAccess' method does not support entities of type 'my_entity'. </span></span></span></p><p><span><span><span><span>Below is the code that I am using to retreive user access rights on entities.</span></span></span></span></p><p><span><span><span><span><pre class="brush: csharp">        protected internal static AccessRights? GetUserAccessRights(string entityName, string UserName, out Guid? UserId)
        {
            // Instantiate the service object
            OrganizationService service = new OrganizationService(&quot;MY_ORG&quot;);

            // Instantiate the context object
            PRMServiceContext context = new PRMServiceContext(service);

            if (entityName != null &amp;&amp; !String.IsNullOrEmpty(entityName) &amp;&amp; !String.IsNullOrEmpty(UserName))
            {
                try
                {
                    // Get the owner id of the user
                    var userId = (from su in context.CreateQuery&lt;SystemUser&gt;()
                                  join sur in context.CreateQuery&lt;SystemUserRoles&gt;()
                                  on su.SystemUserId equals sur.SystemUserId
                                  where su.DomainName == UserName
                                  select su.SystemUserId).FirstOrDefault();

                    Guid? instanceId = null;
                    switch (entityName)
                    {
                        case &quot;contact&quot;:
                            instanceId =
                            (
                                from c in context.CreateQuery&lt;Contact&gt;()
                                where c.Id != null
                                select c.Id
                            ).Take(1).First();
                            break;
                        case &quot;phonecall&quot;:
                            instanceId =
                            (
                                from c in context.CreateQuery&lt;PhoneCall&gt;()
                                where c.Id != null
                                select c.Id
                            ).Take(1).First();
                            break;
                        case &quot;my_entity&quot;:
                            instanceId =
                            (
                                from c in context.CreateQuery&lt;my_entity&gt;()
                                where c.Id != null
                                select c.Id
                            ).Take(1).First();
                            break;
                    }


                    if (userId != null &amp;&amp; instanceId != null)
                    {
                        RetrievePrincipalAccessRequest req = new RetrievePrincipalAccessRequest();
                       
                        //specify team or systemuser you want to get privileges for
                        req.Principal = new EntityReference(&quot;systemuser&quot;, userId.Value);

                        //specify the CRM record you want to check principal permissions for (can be any entity type)
                        req.Target = new EntityReference(entityName, (Guid)instanceId);

                        RetrievePrincipalAccessResponse resp = (RetrievePrincipalAccessResponse)context.Execute(req);
                        context.ClearChanges();

                        ParameterCollection pc = resp.Results;
                        UserId = userId;

                        return resp.AccessRights;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            UserId = null;
            return null;
        }</pre></span></span></span></span></p><p>&nbsp;<span><span>Please help. Thanks.</span></span></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Retrieving-user-privileges-on-entity-using-CRM-2011-SDK-to-Microsoft-Dynamics-CRM-Forum/7c8bce820f914a5d806da0bc017477ba#7c8bce820f914a5d806da0bc017477ba</link>
		<pubDate>Wed, 29 Aug 2012 22:36:06 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Retrieving-user-privileges-on-entity-using-CRM-2011-SDK-to-Microsoft-Dynamics-CRM-Forum/7c8bce820f914a5d806da0bc017477ba#7c8bce820f914a5d806da0bc017477ba</guid>
		<dc:creator>Ashar A. Syed</dc:creator>
		<slash:comments>1</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/asharsyed/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>