locked
How to retrive current user role in plugin in crm 2011 RRS feed

  • Question

  • Hi,

    How can we get current user role in plugin in crm 2011.

    Regards,

    Kishan.

    Tuesday, September 13, 2011 5:00 AM

Answers

  • Hi,

    From the plugin context you can get initiating user like this.

    Guid currentUsrId=context.InitiatingUserId;

    Use FetchXml or RetrieveMultiple to retrive the roles by sending the user id.

    Use the below code 

     QueryExpression query = new QueryExpression()
              {
                EntityName = "role",
                ColumnSet = new ColumnSet("name"),
                LinkEntities = 
                {
                  new LinkEntity
                  {
                    LinkFromEntityName = Role.EntityLogicalName,
                    LinkFromAttributeName = "roleid",
                    LinkToEntityName = SystemUserRoles.EntityLogicalName,
                    LinkToAttributeName = "roleid",
                    LinkCriteria = new FilterExpression
                    {
                      FilterOperator = LogicalOperator.And,
                      Conditions = 
                      {
                        new ConditionExpression
                        {
                          AttributeName = "systemuserid",
                          Operator = ConditionOperator.Equal,
                          Values = { currentUsrId}
                        }
                      }
                    }
                  }
                }
              };
    
              // Obtain results from the query expression.
              EntityCollection ec = _serviceProxy.RetrieveMultiple(query);

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    Sreeni Pavalla

    Saturday, January 26, 2013 4:35 AM
  • Hi,

    You can refer to code in the following Url: http://worldofdynamics.blogspot.com/2011/07/retrieve-user-security-roles-code.html


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, September 13, 2011 5:55 AM

All replies

  • Hi,

    You can refer to code in the following Url: http://worldofdynamics.blogspot.com/2011/07/retrieve-user-security-roles-code.html


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, September 13, 2011 5:55 AM
  • Hi,

    From the plugin context you can get initiating user like this.

    Guid currentUsrId=context.InitiatingUserId;

    Use FetchXml or RetrieveMultiple to retrive the roles by sending the user id.

    Use the below code 

     QueryExpression query = new QueryExpression()
              {
                EntityName = "role",
                ColumnSet = new ColumnSet("name"),
                LinkEntities = 
                {
                  new LinkEntity
                  {
                    LinkFromEntityName = Role.EntityLogicalName,
                    LinkFromAttributeName = "roleid",
                    LinkToEntityName = SystemUserRoles.EntityLogicalName,
                    LinkToAttributeName = "roleid",
                    LinkCriteria = new FilterExpression
                    {
                      FilterOperator = LogicalOperator.And,
                      Conditions = 
                      {
                        new ConditionExpression
                        {
                          AttributeName = "systemuserid",
                          Operator = ConditionOperator.Equal,
                          Values = { currentUsrId}
                        }
                      }
                    }
                  }
                }
              };
    
              // Obtain results from the query expression.
              EntityCollection ec = _serviceProxy.RetrieveMultiple(query);

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    Sreeni Pavalla

    Saturday, January 26, 2013 4:35 AM