/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // For this sample, all required entities are created in the Run() method. // Create/retrieve a user to get associated user details. SystemUser user = _serviceProxy.Retrieve(SystemUser.EntityLogicalName, SystemUserProvider.RetrieveAUserWithoutAnyRoleAssigned(_serviceProxy), new ColumnSet(new String[] { "domainname", "firstname", "lastname" })).ToEntity <SystemUser>(); // Extract the domain, username, firstname and lastname from the user record. String[] userPath = user.DomainName.Split(new char[] { '\\' }); if (userPath.Length > 1) { _domain = userPath[0] + "\\"; _userName = userPath[1]; } else { _domain = String.Empty; _userName = userPath[0]; } _firstName = user.FirstName; _lastName = user.LastName; }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // For this sample, all required entities are created in the Run() method. // Create/Retrieve a user. _userId = SystemUserProvider.RetrieveAUserWithoutAnyRoleAssigned(_serviceProxy); if (_userId != Guid.Empty) { Console.WriteLine("{0} user retrieved.", _userId); } }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // For this sample, all required entities are created in the Run() method. // Create/retrieve a user and associate a role. _userId = SystemUserProvider.RetrieveAUserWithoutAnyRoleAssigned(_serviceProxy); // Find the role. QueryExpression query = new QueryExpression { EntityName = Role.EntityLogicalName, ColumnSet = new ColumnSet("roleid"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "name", Operator = ConditionOperator.Equal, Values = { _givenRole } } } } }; // Get the role. EntityCollection roles = _serviceProxy.RetrieveMultiple(query); if (roles.Entities.Count > 0) { Role salesRole = _serviceProxy.RetrieveMultiple(query).Entities[0].ToEntity <Role>(); // Associate the user with the role for this sample. if (salesRole != null & amp; & _userId != Guid.Empty) { _serviceProxy.Associate( "systemuser", _userId, new Relationship("systemuserroles_association"), new EntityReferenceCollection() { new EntityReference(Role.EntityLogicalName, salesRole.Id) }); } } }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // For this sample, all required entities are created in the Run() method. // Retrieve a user. _userId = SystemUserProvider.RetrieveAUserWithoutAnyRoleAssigned(_serviceProxy); }