locked
CRM 2013 Check If logged in user have User level create privilege for particular entity. RRS feed

  • Question

  • Hello,

    I have a requirement. Where i want to find if logged in user has User level permission on any entity or not.

    Do i have to check for Every role assigned to user?

    Can we directly fetch previlege entity and check using below fetchXML? I am using soap request and fetching previlege.. 

    I didn't specify anywhere user condition in below code.. Does it consider user condition?

    <fetch mapping="logical">',
    '<entity name="privilege">',
    '<attribute name="name" />',
     '<attribute name="accessright" />',
      '<attribute name="canbebasic" />',
     '<filter type="and">',
    '<condition attribute="name" operator="eq" value="prvcreate' + entity + '" />',
    '</filter>',
     '</entity>',
    '</fetch>'

    I know there is RetrievePriciaplAccessRequest for the same.. 

    Please Note: i am using JavaScript Soap request and CRM 2013.

    Thanks!

    Wednesday, March 12, 2014 9:37 AM

All replies

  • Hi Kaushal,

    You could try something like this, which retrieves User Privileges

    http://mileyja.blogspot.com.es/2011/05/using-retrieveuserprivileges-requests.html


    Admin QuikView Solution for CRM 2013

    Wednesday, March 12, 2014 9:42 AM
  • Hello,

    I am aware about this request as informed eralier.

    Why can't we retrieve Previlege entity as given above?

    As informed earlier i want to check if user has user level Create previlege on entity.

    Thanks!



    • Edited by Kaushal123 Wednesday, March 12, 2014 10:33 AM
    Wednesday, March 12, 2014 10:33 AM
  • HI,

    You can use this tike:

    <fetch mapping="logical" version="1.0">
        <entity name="privilege">
            <attribute name="name" />
            <attribute name="accessright" />
            <attribute name="canbebasic" />
            <filter>
                <condition attribute="name" operator="eq" value="prvcreateaccount" />
            </filter>
        </entity>
    </fetch>


    Result show:

    <resultset >
        <result>
            <name>prvCreateAccount</name>
            <accessright formattedvalue="32">32</accessright>
            <canbebasic name="Yes">1</canbebasic>
            <privilegeid>{D26FE964-230B-42DD-AD93-5CC879DE411E}</privilegeid>
        </result>
    </resultset>


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Wednesday, March 12, 2014 10:46 AM
  • Hello,

    Thanks for your reply. you have posted same code. I am already getting result..

    Please read my condition.

    I didn't specify anywhere user condition in above code.. Does it consider current user condition or we have to specify current user condition implicitly?

    How can we do that.

    Thanks!



    • Edited by Kaushal123 Wednesday, March 12, 2014 10:57 AM
    Wednesday, March 12, 2014 10:57 AM
  • If you are trying to check the current user have this privilege like (prvCreateOpportunity)

    it will only retrieve record present in table/entity privilege


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    • Proposed as answer by Mr. Santosh Bhagat Wednesday, March 12, 2014 11:09 AM
    • Unproposed as answer by Kaushal123 Thursday, March 13, 2014 6:38 AM
    Wednesday, March 12, 2014 11:09 AM
  • Hello Santosh,

    Do you think bellow code checks for current user privilege? We didn't specify the condition anywhere for current user.

    <fetch mapping="logical" version="1.0">
        <entity name="privilege">
            <attribute name="name" />
            <attribute name="accessright" />
            <attribute name="canbebasic" />
            <filter>
                <condition attribute="name" operator="eq" value="prvcreateaccount" />
            </filter>
        </entity>
    </fetch>

    I want how we can get the current users privilege.

    Can somebody help?

    Thanks!

    Wednesday, March 12, 2014 11:44 AM
  • Hello MVP's and Experts,

    Please provide some guidance.

    Thanks

    Thursday, March 13, 2014 7:18 AM
  • Hi kaushual ,

    I was little busy .

    use Xrm.Page.context.getUserId() to get user id

    Use this fetch:

    <fetch mapping="logical" count="50" version="1.0">
        <entity name="role">
            <attribute name="name" />
            <link-entity name="systemuserroles" from="roleid" to="roleid">
                <link-entity name="systemuser" from="systemuserid" to="systemuserid">
                    <filter>
                        <condition attribute="systemuserid" operator="eq" value="YOURID" />
                    </filter>
                </link-entity>
            </link-entity>
            <link-entity name="roleprivileges" from="roleid" to="roleid">
                <link-entity name="privilege" from="privilegeid" to="privilegeid">
                    <attribute name="name" />
                    <attribute name="privilegeid" />
                </link-entity>
            </link-entity>
        </entity>
    </fetch>


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Thursday, March 13, 2014 8:50 AM
  • Hi Santosh,

    The Javascript retrieves the roles of the user and privilege but it shows canbedeep, canbelocal, canbeglobal to true even if user role have only user level create privilege.

    '<fetch mapping="logical" >',

        '<entity name="role">',
            '<attribute name="name" />',
            '<link-entity name="systemuserroles" from="roleid" to="roleid">',
                '<link-entity name="systemuser" from="systemuserid" to="systemuserid">',
                    '<filter>',
                        '<condition attribute="systemuserid" operator="eq-userid"/>',
                    '</filter>',
               ' </link-entity>',
            '</link-entity>',
           ' <link-entity name="roleprivileges" from="roleid" to="roleid">',
               ' <link-entity name="privilege" from="privilegeid" to="privilegeid">',
                   ' <attribute name="canbebasic" />',
                    ' <attribute name="canbedeep" />',
                     ' <attribute name="canbelocal" />',
                      ' <attribute name="canbeglobal" />',
                     '  <attribute name="accessright" />',
                      '<filter type="and">',
               '<condition attribute="name" operator="eq" value="prvcreate' + entity + '" />',
               '</filter>',
                    '  </link-entity>',
                 ' </link-entity>',
              '</entity>',
         ' </fetch>'

    Would you please help?

    Thanks!


    • Edited by Kaushal123 Thursday, March 20, 2014 1:20 PM
    Thursday, March 20, 2014 1:19 PM