Tag Cloud

CRM 2011 (161) CRM 4.0 (144) C# (116) JScript (109) Plugin (92) Registry (90) Techpedia (77) PyS60 (68) WScript (43) Plugin Message (31) Exploit (27) ShellCode (26) FAQ (22) JavaScript (21) Killer Codes (21) Hax (18) VB 6.0 (17) Commands (16) VBScript (16) Quotes (15) Turbo C++ (13) WMI (13) Security (11) 1337 (10) Tutorials (10) Asp.Net (9) Safe Boot (9) Python (8) Interview Questions (6) video (6) Ajax (5) VC++ (5) WebService (5) Workflow (5) Bat (4) Dorks (4) Sql Server (4) Aptitude (3) Picklist (3) Tweak (3) WCF (3) regex (3) Config (2) LINQ (2) PHP (2) Shell (2) Silverlight (2) TSql (2) flowchart (2) serialize (2) ASHX (1) CRM 4.0 Videos (1) Debug (1) FetchXml (1) GAC (1) General (1) Generics (1) HttpWebRequest (1) InputParameters (1) Lookup (1) Offline Plug-ins (1) OutputParameters (1) Plug-in Constructor (1) Protocol (1) RIA (1) Sharepoint (1) Walkthrough (1) Web.config (1) design patterns (1) generic (1) iframe (1) secure config (1) unsecure config (1) url (1)

Pages

Thursday, May 02, 2013

Retrieve the Roles for a User

This sample shows how to build a QueryExpression to for use with RetrieveMultiple to find all the roles for a user. To do this, you have to build a query for roles where you join 'role' to 'systemuserroles', and then join systemuserroles' to 'systemuser' and add a condition where systemuser.systemuserid equals the attribute UserId.




// Retrieve the GUID of the logged on user.
WhoAmIRequest whoReq = new WhoAmIRequest();
WhoAmIResponse whoResp = (WhoAmIResponse) service.Execute(whoReq);
Guid userid = whoResp.UserId;

// Create a QueryExpression.
QueryExpression qe = new QueryExpression();
qe.EntityName = "role";
// Be aware that using AllColumns may adversely affect
// performance and cause unwanted cascading in subsequent
// updates. A best practice is to retrieve the least amount of
// data required.
qe.ColumnSet = new AllColumns();

// Set up the join between the role entity
// and the intersect table systemuserroles.
LinkEntity le = new LinkEntity();
le.LinkFromEntityName = "role";
le.LinkFromAttributeName = "roleid";
le.LinkToEntityName = "systemuserroles";
le.LinkToAttributeName = "roleid";

// Set up the join between the intersect table
// systemuserroles and the systemuser entity.
LinkEntity le2 = new LinkEntity();
le2.LinkFromEntityName = "systemuserroles";
le2.LinkFromAttributeName = "systemuserid";
le2.LinkToEntityName = "systemuser";
le2.LinkToAttributeName = "systemuserid";

// The condition is to find the user ID.
ConditionExpression ce = new ConditionExpression();
ce.AttributeName = "systemuserid";
ce.Operator = ConditionOperator.Equal;
ce.Values = new object[]{userid};

le2.LinkCriteria = new FilterExpression();
le2.LinkCriteria.Conditions = new ConditionExpression[]{ce};

le.LinkEntities = new LinkEntity[]{le2};
qe.LinkEntities = new LinkEntity[]{le};

// Execute the query.
BusinessEntityCollection bec = service.RetrieveMultiple(qe);





Retrieve the Roles for a User

This sample shows how to build a QueryExpression to for use with RetrieveMultiple to find all the roles for a user. To do this, you have to build a query for roles where you join 'role' to 'systemuserroles', and then join systemuserroles' to 'systemuser' and add a condition where systemuser.systemuserid equals the attribute UserId.



   1:  //# Retrieve the Roles for a User #//

   2:   

   3:  // Retrieve the GUID of the logged on user.

   4:  WhoAmIRequest whoReq = new WhoAmIRequest();

   5:  WhoAmIResponse whoResp = (WhoAmIResponse) service.Execute(whoReq);

   6:  Guid userid = whoResp.UserId;

   7:   

   8:  // Create a QueryExpression.

   9:  QueryExpression qe = new QueryExpression();

  10:  qe.EntityName = "role";

  11:  // Be aware that using AllColumns may adversely affect

  12:  // performance and cause unwanted cascading in subsequent 

  13:  // updates. A best practice is to retrieve the least amount of 

  14:  // data required.

  15:  qe.ColumnSet = new AllColumns();

  16:   

  17:  // Set up the join between the role entity

  18:  // and the intersect table systemuserroles.

  19:  LinkEntity le = new LinkEntity();

  20:  le.LinkFromEntityName = "role";

  21:  le.LinkFromAttributeName = "roleid";

  22:  le.LinkToEntityName = "systemuserroles";

  23:  le.LinkToAttributeName = "roleid";

  24:   

  25:  // Set up the join between the intersect table

  26:  // systemuserroles and the systemuser entity.

  27:  LinkEntity le2 = new LinkEntity();

  28:  le2.LinkFromEntityName = "systemuserroles";

  29:  le2.LinkFromAttributeName = "systemuserid";

  30:  le2.LinkToEntityName = "systemuser";

  31:  le2.LinkToAttributeName = "systemuserid";

  32:   

  33:  // The condition is to find the user ID.

  34:  ConditionExpression ce = new ConditionExpression();

  35:  ce.AttributeName = "systemuserid";

  36:  ce.Operator = ConditionOperator.Equal;

  37:  ce.Values = new object[]{userid};

  38:   

  39:  le2.LinkCriteria = new FilterExpression();

  40:  le2.LinkCriteria.Conditions = new ConditionExpression[]{ce};

  41:   

  42:  le.LinkEntities = new LinkEntity[]{le2};

  43:  qe.LinkEntities = new LinkEntity[]{le};

  44:   

  45:  // Execute the query.

  46:  BusinessEntityCollection bec = service.RetrieveMultiple(qe);