/// <summary> /// Creates any entity records that this sample requires. /// </summary> public static void CreateRequiredRecords(CrmServiceClient service) { // Get the user from the Helper. _userId = SystemUserProvider.RetrieveMarketingManager(service); Console.Write("User retrieved, "); //_userId = ((WhoAmIResponse)service.Execute(new WhoAmIRequest())).OrganizationId; //Console.Write("User retrieved, "); // Retrieve the security role needed to assign to the user. QueryExpression roleQuery = new QueryExpression { EntityName = Role.EntityLogicalName, ColumnSet = new ColumnSet("roleid"), Criteria = { Conditions = { new ConditionExpression("name", ConditionOperator.Equal, "Marketing Manager") } } }; Role role = (Role)service.RetrieveMultiple(roleQuery).Entities[0]; _roleId = role.Id; // Retrieve the default business unit needed to create the team. QueryExpression queryDefaultBusinessUnit = new QueryExpression { EntityName = BusinessUnit.EntityLogicalName, ColumnSet = new ColumnSet("businessunitid"), Criteria = { Conditions = { new ConditionExpression("parentbusinessunitid", ConditionOperator.Null) } } }; // Execute the query. BusinessUnit defaultBusinessUnit = (BusinessUnit)service.RetrieveMultiple( queryDefaultBusinessUnit).Entities[0]; // Instantiate a team entity record and set its property values. // See the Entity Metadata topic in the SDK documentation to determine // which attributes must be set for each entity. Team setupTeam = new Team { Name = "CDS Management Team", BusinessUnitId = new EntityReference(BusinessUnit.EntityLogicalName, defaultBusinessUnit.Id) }; // Create a team record. _teamId = service.Create(setupTeam); Console.Write("Created Team, "); }
/// <summary> /// This method creates any entity records that this sample requires. /// Creates the email activity. /// </summary> public static void CreateRequiredRecords(CrmServiceClient service) { // Retrieve a sales manager. _salesManagerId = SystemUserProvider.RetrieveMarketingManager(service); // Create an account. var account = new Account() { Name = "Fourth Coffee", Address1_City = "Seattle" }; _accountId = service.Create(account); Console.WriteLine("Required records have been created."); }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public static void CreateRequiredRecords(CrmServiceClient service) { #region Create or Retrieve the necessary system users // Retrieve a sales manager. _salesManagerId = SystemUserProvider.RetrieveMarketingManager(service); #endregion #region Create PhoneCall record and supporting account Account newAccount = new Account { Name = "Margie's Travel", Address1_PostalCode = "99999" }; _accountId = (service.Create(newAccount)); newAccount.Id = _accountId; // Create Guids for PhoneCalls _phoneCallId = Guid.NewGuid(); _phoneCall2Id = Guid.NewGuid(); // Create ActivityPartys for the phone calls' "From" field. ActivityParty activityParty = new ActivityParty() { PartyId = newAccount.ToEntityReference(), ActivityId = new EntityReference { Id = _phoneCallId, LogicalName = PhoneCall.EntityLogicalName, }, ParticipationTypeMask = new OptionSetValue(9) }; ActivityParty activityPartyClosed = new ActivityParty() { PartyId = newAccount.ToEntityReference(), ActivityId = new EntityReference { Id = _phoneCall2Id, LogicalName = PhoneCall.EntityLogicalName, }, ParticipationTypeMask = new OptionSetValue(9) }; // Create an open phone call. PhoneCall phoneCall = new PhoneCall() { Id = _phoneCallId, Subject = "Sample Phone Call", DirectionCode = false, To = new ActivityParty[] { activityParty } }; service.Create(phoneCall); // Create a second phone call to close phoneCall = new PhoneCall() { Id = _phoneCall2Id, Subject = "Sample Phone Call 2", DirectionCode = false, To = new ActivityParty[] { activityParty }, ActualEnd = DateTime.Now }; service.Create(phoneCall); // Close the second phone call. SetStateRequest closePhoneCall = new SetStateRequest() { EntityMoniker = phoneCall.ToEntityReference(), State = new OptionSetValue(1), Status = new OptionSetValue(4) }; service.Execute(closePhoneCall); #endregion }