/// <summary> /// This method creates any entity records that this sample requires. /// Creates the email activity. /// </summary> public static void CreateRequiredRecords(CrmServiceClient service) { // For this sample, all required entities are created in the Run() method. // Create/Retrieve a user. _userId = SystemUserProvider.RetrieveAUserWithoutAnyRoleAssigned(service); if (_userId != Guid.Empty) { Console.WriteLine("{0} user retrieved.", _userId); } }
/// <summary> /// This method creates any entity records that this sample requires. /// Creates the email activity. /// </summary> public static void CreateRequiredRecords(CrmServiceClient service) { // Create/retrieve a user and associate a role. _userId = SystemUserProvider.RetrieveAUserWithoutAnyRoleAssigned(service); // Find the role. var 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 = service.RetrieveMultiple(query); if (roles.Entities.Count > 0) { Role salesRole = service.RetrieveMultiple(query).Entities[0].ToEntity <Role>(); // Associate the user with the role for this sample. if (salesRole != null && _userId != Guid.Empty) { service.Associate( "systemuser", _userId, new Relationship("systemuserroles_association"), new EntityReferenceCollection() { new EntityReference(Role.EntityLogicalName, salesRole.Id) }); } } }