/// <summary> /// Add a existing <c>Privilege</c> to a <c>Role</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.addprivilegesrolerequest(v=crm.7).aspx /// </para> /// </summary> /// <param name="roleId"></param> /// <param name="privilege"></param> /// <returns><see cref="AddPrivilegesRoleResponse"/></returns> public AddPrivilegesRoleResponse AddPrivilege(Guid roleId, RolePrivilege privilege) { ExceptionThrow.IfGuidEmpty(roleId, "roleId"); ExceptionThrow.IfNull(privilege, "privilege"); AddPrivilegesRoleRequest request = new AddPrivilegesRoleRequest() { RoleId = roleId, Privileges = new RolePrivilege[] { privilege } }; return((AddPrivilegesRoleResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Add bulk <c>System User</c> data into to the <c>Team</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.addmembersteamrequest(v=crm.7).aspx /// </para> /// </summary> /// <param name="teamId"><c>Team</c> Id</param> /// <param name="systemuserIdList"><c>System User</c> Id list</param> /// <returns><see cref="AddMembersTeamResponse"/></returns> public AddMembersTeamResponse AddMember(Guid teamId, List <Guid> systemuserIdList) { ExceptionThrow.IfGuidEmpty(teamId, "teamId"); ExceptionThrow.IfNullOrEmpty(systemuserIdList.ToArray(), "systemuserIdList"); AddMembersTeamRequest request = new AddMembersTeamRequest() { TeamId = teamId, MemberIds = systemuserIdList.ToArray() }; return((AddMembersTeamResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Change the parent <c>Business Unit</c> for specified <c>Team</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.setparentteamrequest(v=crm.7).aspx /// </para> /// </summary> /// <param name="teamId"><c>Team</c> Id</param> /// <param name="businessUnitId"><c>Business Unit</c> Id</param> public void ChangeParent(Guid teamId, Guid businessUnitId) { ExceptionThrow.IfGuidEmpty(teamId, "teamId"); ExceptionThrow.IfGuidEmpty(businessUnitId, "businessUnitId"); SetParentTeamRequest request = new SetParentTeamRequest() { TeamId = teamId, BusinessId = businessUnitId }; this.OrganizationService.Execute(request); }
/// <summary> /// Retrieve all private <c>Queue</c> data of a specified <c>System User</c> and optionally all public queues. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.retrieveuserqueuesrequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="systemuserId"><c>System User</c> Id</param> /// <param name="includePublic">Set <c>true</c>, if you need all <c>Queue</c> data (with private and public). Otherwise set <c>false</c> </param> /// <returns> /// <see cref="EntityCollection"/> for <c>Queue</c> data /// </returns> public EntityCollection GetBySystemUserId(Guid systemuserId, bool includePublic = false) { ExceptionThrow.IfGuidEmpty(systemuserId, "systemuserId"); RetrieveUserQueuesRequest request = new RetrieveUserQueuesRequest() { UserId = systemuserId, IncludePublic = includePublic }; RetrieveUserQueuesResponse serviceResponse = (RetrieveUserQueuesResponse)this.OrganizationService.Execute(request); return(serviceResponse.EntityCollection); }
/// <summary> /// Pick item from <c>Queue</c> to <c>System User</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.pickfromqueuerequest(v=crm.7).aspx /// </para> /// </summary> /// <param name="queueItemId"><c>Queue</c> Id</param> /// <param name="systemuserId"><c>System User</c> Id</param> /// <param name="shouldRemoved">Set <c>true</c>, if you want remove item from Queue. Otherwise set <c>false</c> </param> /// <returns> /// <see cref="PickFromQueueResponse"/> /// </returns> public PickFromQueueResponse PickFromQueue(Guid queueItemId, Guid systemuserId, bool shouldRemoved = false) { ExceptionThrow.IfGuidEmpty(queueItemId, "queueItemId"); ExceptionThrow.IfGuidEmpty(systemuserId, "systemuserId"); PickFromQueueRequest request = new PickFromQueueRequest() { QueueItemId = queueItemId, RemoveQueueItem = shouldRemoved, WorkerId = systemuserId }; return((PickFromQueueResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Validate <c>Email</c> entity with required attributes. /// </summary> /// <param name="entity"></param> void ValidateEmailEntity(Entity entity) { ExceptionThrow.IfNull(entity, "entity"); ExceptionThrow.IfNullOrEmpty(entity.LogicalName, "Entity.LogicalName"); ExceptionThrow.IfNotExpectedValue(entity.LogicalName.Trim().ToLower(), "Entity.LogicalName", "email", "Entity.LogicalName must be 'email'"); var sender = GetFrom(entity); ExceptionThrow.IfNull(sender, "email.from"); ExceptionThrow.IfGuidEmpty(sender.Id, "email.from.id"); ExceptionThrow.IfNullOrEmpty(sender.LogicalName, "email.from.LogicalName"); ExceptionThrow.IfNullOrEmpty(((EntityCollection)entity["to"]).Entities, "email.to"); }
/// <summary> /// Assign the specified record to a new owner (user or team). /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.assignrequest(v=crm.7).aspx /// </para> /// </summary> /// <param name="assigneeType"> /// <see cref="PrincipalType"/> /// </param> /// <param name="assigneeId"></param> /// <param name="targetEntityLogicalName"></param> /// <param name="targetId"></param> public void Assign(PrincipalType assigneeType, Guid assigneeId, string targetEntityLogicalName, Guid targetId) { ExceptionThrow.IfGuidEmpty(assigneeId, "assigneeId"); ExceptionThrow.IfGuidEmpty(targetId, "targetId"); ExceptionThrow.IfNullOrEmpty(targetEntityLogicalName, "targetEntityLogicalName"); AssignRequest request = new AssignRequest() { Assignee = new EntityReference(assigneeType.Description(), assigneeId), Target = new EntityReference(targetEntityLogicalName, targetId) }; this.OrganizationService.Execute(request); }
/// <summary> /// Change current state and status information for given record. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.setstaterequest(v=crm.7).aspx /// </para> /// </summary> /// <param name="id">Record Id</param> /// <param name="entityLogicalName">Record logical name</param> /// <param name="stateCode">State code</param> /// <param name="statusCode">Status code</param> public void UpdateState(Guid id, string entityLogicalName, int stateCode, int statusCode) { ExceptionThrow.IfGuidEmpty(id, "id"); ExceptionThrow.IfNullOrEmpty(entityLogicalName, "entityLogicalName"); var request = new SetStateRequest() { EntityMoniker = new EntityReference(entityLogicalName, id), State = new OptionSetValue(stateCode), Status = new OptionSetValue(statusCode) }; this.OrganizationService.Execute(request); }
/// <summary> /// Search multiple resources for available time block that match the specified parameters. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.querymultipleschedulesrequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="resourceIdList"></param> /// <param name="start"></param> /// <param name="end"></param> /// <param name="timecodes"></param> /// <returns><see cref="QueryMultipleSchedulesResponse"/></returns> public QueryMultipleSchedulesResponse GetWorkingHours(List <Guid> resourceIdList, DateTime start, DateTime end, TimeCode[] timecodes) { ExceptionThrow.IfNullOrEmpty(resourceIdList, "resourceIdList"); QueryMultipleSchedulesRequest request = new QueryMultipleSchedulesRequest() { ResourceIds = resourceIdList.ToArray(), Start = start, End = end, TimeCodes = timecodes }; return((QueryMultipleSchedulesResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Search the specified resource for an available time block that matches the specified parameters. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.queryschedulerequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="resourceId">Resource Id</param> /// <param name="start">Start of the time slot.</param> /// <param name="end">End of the time slot.</param> /// <param name="timecode"> /// <see cref="TimeCode"/> /// </param> /// <returns><see cref="QueryScheduleResponse"/></returns> public QueryScheduleResponse GetWorkingHours(Guid resourceId, DateTime start, DateTime end, TimeCode timecode) { ExceptionThrow.IfGuidEmpty(resourceId, "resourceId"); QueryScheduleRequest request = new QueryScheduleRequest() { ResourceId = resourceId, Start = start, End = end, TimeCodes = new TimeCode[] { timecode } }; return((QueryScheduleResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// <c>Monthly</c> recurrence. /// </summary> /// <param name="option"></param> /// <param name="day"></param> /// <param name="interval"></param> /// <returns></returns> public XrmRecurringAppointment Monthly(MonthlyOption option, DayOfWeek day, int interval) { ExceptionThrow.IfEquals(interval, "interval", 0); ExceptionThrow.IfNegative(interval, "interval"); SetRecurrence(); _recurrencePattern = RecurrencePatternType.Monthly; _monthlyOption = option; _interval = interval; _dayOfWeeksValue = (int)day; return(this); }
/// <summary> /// Add an item to <c>Campaign</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.additemcampaignrequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="campaignId"><c>Campaign</c> Id</param> /// <param name="itemType"><see cref="ItemTypeCode"/></param> /// <param name="itemId">Item Id</param> /// <returns> /// Returns created Item Id in <see cref="AddItemCampaignResponse.CampaignItemId"/> property. /// </returns> public AddItemCampaignResponse AddItem(Guid campaignId, ItemTypeCode itemType, Guid itemId) { ExceptionThrow.IfGuidEmpty(campaignId, "campaignId"); ExceptionThrow.IfGuidEmpty(itemId, "itemId"); AddItemCampaignRequest request = new AddItemCampaignRequest() { CampaignId = campaignId, EntityId = itemId, EntityName = itemType.Description() }; return((AddItemCampaignResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Remove all access to a record for the specified principal. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.revokeaccessrequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="shareToPrincipal"><see cref="PrincipalType"/></param> /// <param name="shareToId"></param> /// <param name="targetEntityLogicalName"></param> /// <param name="targetId"></param> /// <returns> /// <see cref="RevokeAccessResponse"/> /// </returns> public RevokeAccessResponse RemoveShare(PrincipalType shareToPrincipal, Guid shareToId, string targetEntityLogicalName, Guid targetId) { ExceptionThrow.IfGuidEmpty(shareToId, "shareToId"); ExceptionThrow.IfGuidEmpty(targetId, "targetId"); ExceptionThrow.IfNullOrEmpty(targetEntityLogicalName, "targetEntityLogicalName"); RevokeAccessRequest request = new RevokeAccessRequest() { Revokee = new EntityReference(shareToPrincipal.Description(), shareToId), Target = new EntityReference(targetEntityLogicalName, targetId) }; return((RevokeAccessResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Retrieve the <c>access rights</c> of the specified user to the specified record. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.retrieveprincipalaccessrequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="id"></param> /// <param name="targetRecordLogicalName"></param> /// <param name="targetRecordId"></param> /// <returns> /// <see cref="RetrievePrincipalAccessResponse"/>. /// You can get <c>Access Rights</c> from <see cref="RetrievePrincipalAccessResponse.AccessRights"/> propert. /// </returns> public RetrievePrincipalAccessResponse GetAccessRights(Guid id, string targetRecordLogicalName, Guid targetRecordId) { ExceptionThrow.IfGuidEmpty(id, "id"); ExceptionThrow.IfGuidEmpty(targetRecordId, "entityId"); ExceptionThrow.IfNullOrEmpty(targetRecordLogicalName, "entityName"); RetrievePrincipalAccessRequest request = new RetrievePrincipalAccessRequest() { Principal = new EntityReference(this.EntityName, id), Target = new EntityReference(targetRecordLogicalName, targetRecordId) }; return((RetrievePrincipalAccessResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Generate a <c>SalesOrder</c> from the specified <c>Opportunity</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.generatesalesorderfromopportunityrequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="opportunityId"><c>Opportunity</c> Id</param> /// <param name="retrievedColumns"> /// Default attributes are "salesorderid", "name", "ordernumber", "totalamount". /// If you need more or different attributes please set this parameter /// </param> /// <returns> /// Returns created <c>SalesOrder</c> in <see cref="GenerateSalesOrderFromOpportunityResponse.Entity"/> property with attributes that defined in <c>retrievedQuoteColums</c> parameter /// </returns> public GenerateSalesOrderFromOpportunityResponse CreateFromOpportunity(Guid opportunityId, params string[] retrievedColumns) { ExceptionThrow.IfGuidEmpty(opportunityId, "opportunityId"); string[] columns = !retrievedColumns.IsNullOrEmpty() ? retrievedColumns : _salesorderColumns; GenerateSalesOrderFromOpportunityRequest request = new GenerateSalesOrderFromOpportunityRequest() { OpportunityId = opportunityId, ColumnSet = new ColumnSet(columns) }; return((GenerateSalesOrderFromOpportunityResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Create <c>Translation</c> of a <c>Knowledge Article</c>. /// Please note that this creates a new <c>Knowledge Article</c> record with the <c>Title</c>, <c>Content</c>, <c>Description</c> and <c>Keywords</c> copied from the source record to the new record /// and the language of the new record set to the one you specified in the <paramref name="languageId"/> parameter. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.createknowledgearticletranslationrequest.aspx /// </para> /// </summary> /// <param name="sourceId"><c>Knowledge Article</c> Id</param> /// <param name="isMajor">Indicate create a major or minor version of the knowledge article</param> /// <param name="languageId"> /// <c>LanguageLocale</c> Id. /// You can also use <see cref="LanguageCodeList"/> enumaration to find related Language Id (<see cref="Guid"/>). /// <para> /// Please note that the GUID value of the <c>primary key (LanguageLocaleId)</c> for each language record in the <c>LanguageLocale</c> entity is the same across all Dynamics 365 organizations. /// For more information look at https://msdn.microsoft.com/en-us/library/gg309345.aspx#Translation /// </para> /// For more information about <c>LanguageLocale</c> entity look at https://msdn.microsoft.com/en-us/library/mt607524.aspx /// </param> /// <returns> /// Returns newly created <c>Knowledge Article</c> by <see cref="EntityReference"/> in <see cref="CreateKnowledgeArticleTranslationResponse.CreateKnowledgeArticleTranslation"/> property. /// </returns> public CreateKnowledgeArticleTranslationResponse Translate(Guid sourceId, bool isMajor, Guid languageId) { ExceptionThrow.IfGuidEmpty(sourceId, "sourceId"); ExceptionThrow.IfGuidEmpty(languageId, "languageId"); CreateKnowledgeArticleTranslationRequest request = new CreateKnowledgeArticleTranslationRequest() { IsMajor = isMajor, Language = new EntityReference("languagelocale ", languageId), Source = new EntityReference(this.EntityName, sourceId) }; return((CreateKnowledgeArticleTranslationResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Convert a <c>SalesOrder</c> to an <c>Invoice</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.convertsalesordertoinvoicerequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="id"><c>Salesorder</c> Id</param> /// <param name="retrievedColumns"> /// Default attributes are "invoiceid", "name", "invoicenumber", "totalamount". /// If you need more or different attributes please set this parameter /// </param> /// <returns> /// Returns created <c>Invoice</c> in <see cref="ConvertSalesOrderToInvoiceResponse.Entity"/>property with attributes that defined in <c>retrievedQuoteColums</c> parameter /// </returns> public ConvertSalesOrderToInvoiceResponse ConvertToInvoice(Guid id, params string[] retrievedColumns) { ExceptionThrow.IfGuidEmpty(id, "id"); string[] columns = !retrievedColumns.IsNullOrEmpty() ? retrievedColumns : _invoiceColumns; ConvertSalesOrderToInvoiceRequest request = new ConvertSalesOrderToInvoiceRequest() { SalesOrderId = id, ColumnSet = new ColumnSet(columns) }; return((ConvertSalesOrderToInvoiceResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Retrieve all the <c>Business Unit</c> list in the business unit hierarchy. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.retrievebusinesshierarchybusinessunitrequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="id">Parent <c>Business Unit</c> Id</param> /// <returns><see cref="EntityCollection"/> for <c>Business Unit</c> list</returns> public EntityCollection GetHierarchy(Guid id) { ExceptionThrow.IfGuidEmpty(id, "id"); RetrieveBusinessHierarchyBusinessUnitRequest request = new RetrieveBusinessHierarchyBusinessUnitRequest() { ColumnSet = new ColumnSet(true), EntityId = id }; RetrieveBusinessHierarchyBusinessUnitResponse serviceResponse = (RetrieveBusinessHierarchyBusinessUnitResponse)this.OrganizationService.Execute(request); return(serviceResponse.EntityCollection); }
/// <summary> /// Create a <c>Campaign</c>. /// </summary> /// <param name="name">Name</param> /// <param name="code">Code. /// If you don't provide this data, MS CRM gives an automated number /// </param> /// <param name="typeCode"><see cref="CampaignTypeCode"/></param> /// <param name="description"></param> /// <param name="transactioncurrencyId"></param> /// <param name="actualStart">Actual Start date</param> /// <param name="actualEnd">Actual End date</param> /// <param name="proposedStart">Propesed Start date</param> /// <param name="proposedEnd">Proposed End date</param> /// <param name="status"><see cref="CampaignActiveStatusCode"/> status code</param> /// <param name="customStatusCode">If you're using your custom statuscodes set this, otherwise you can set "0 (zero)" or null</param> /// <returns> /// Created record Id (<see cref="Guid"/>) /// </returns> public Guid Create(string name, string code, CampaignTypeCode typeCode, string description, Guid transactioncurrencyId, DateTime?actualStart, DateTime?actualEnd, DateTime?proposedStart, DateTime?proposedEnd, CampaignActiveStatusCode status, int customStatusCode = 0) { ExceptionThrow.IfNullOrEmpty(name, "name"); ExceptionThrow.IfGuidEmpty(transactioncurrencyId, "transactioncurrencyId"); int statusCode = (int)status; if (status == CampaignActiveStatusCode.CustomStatusCode) { ExceptionThrow.IfNegative(customStatusCode, "customStatusCode"); statusCode = customStatusCode; } Entity entity = new Entity(this.EntityName); entity["name"] = name; entity["typecode"] = new OptionSetValue((int)typeCode); entity["transactioncurrencyid"] = new EntityReference("transactioncurrency", transactioncurrencyId); entity["istemplate"] = false; entity["description"] = description; entity["statuscode"] = new OptionSetValue(statusCode); if (!string.IsNullOrEmpty(code)) { entity["codename"] = code; } if (actualStart.HasValue && actualStart.Value != DateTime.MinValue) { entity["actualstart"] = actualStart.Value; } if (actualEnd.HasValue && actualEnd.Value != DateTime.MinValue) { entity["actualend"] = actualEnd.Value; } if (proposedStart.HasValue && proposedStart.Value != DateTime.MinValue) { entity["proposedstart"] = proposedStart.Value; } if (proposedEnd.HasValue && proposedEnd.Value != DateTime.MinValue) { entity["proposedend"] = proposedEnd.Value; } return(this.OrganizationService.Create(entity)); }
/// <summary> /// Get <c>Role</c> Id by specified name. /// </summary> /// <param name="roleName"></param> /// <returns><c>Role</c> Id (<see cref="Guid"/>)</returns> public Guid GetId(string roleName) { ExceptionThrow.IfNullOrEmpty(roleName, "roleName"); Guid result = Guid.Empty; var serviceResponse = this.GetByName(roleName, "roleid"); if (serviceResponse != null && !serviceResponse.Id.IsGuidEmpty()) { result = serviceResponse.Id; } return(result); }
/// <summary> /// Add <c>recurrence</c> information to an existing <c>appointment</c>. /// Please note that when you convert an existing appointment to a recurring appointment, the data from the existing appointment is copied to a new recurring appointment master instance and the existing appointment record is deleted. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.addrecurrencerequest(v=crm.7).aspx /// </para> /// </summary> /// <param name="appointmentId"><c>Appointment</c> Id</param> /// <param name="recurringAppointment"> /// Recurring Appointment entity (<see cref="Entity"/>) /// </param> /// <returns> /// Newly created <c>Recurring Appointment</c> Id (<see cref="Guid"/>) /// </returns> public Guid AddRecurrence(Guid appointmentId, Entity recurringAppointment) { ExceptionThrow.IfGuidEmpty(appointmentId, "appointmentId"); ExceptionThrow.IfNull(recurringAppointment, "recurringAppointment"); ExceptionThrow.IfNullOrEmpty(recurringAppointment.LogicalName, "Entity.LogicalName"); ExceptionThrow.IfNotExpectedValue(recurringAppointment.LogicalName, "Entity.LogicalName", "recurringappointmentmaster"); AddRecurrenceRequest request = new AddRecurrenceRequest() { AppointmentId = appointmentId, Target = recurringAppointment }; return(((AddRecurrenceResponse)this.OrganizationService.Execute(request)).id); }
/// <summary> /// <c>Yearly</c> recurrence with exact date. /// </summary> /// <param name="month"></param> /// <param name="day"></param> /// <param name="interval"><c>Recur every X years</c> interval.</param> /// <returns></returns> public XrmRecurringAppointment Yearly(Month month, int day, int interval) { ExceptionThrow.IfEquals(day, "day", 0); ExceptionThrow.IfNegative(day, "day"); SetRecurrence(); _isFirstOption = true; _recurrencePattern = RecurrencePatternType.Yearly; _interval = interval; _dayNumber = day; _month = month; return(this); }
/// <summary> /// Retrieve <see cref="FileInfo"/> data from <c>Base64</c> content. /// </summary> /// <param name="content"><c>Base64</c> content</param> /// <returns> /// <see cref="FileInfo"/> /// </returns> public static FileInfo GetFileInfoFromBase64(string content) { ExceptionThrow.IfNullOrEmpty(content, "Content"); string tempFileName = Path.GetTempFileName(); byte[] fileByte = Convert.FromBase64String(content); File.WriteAllBytes(tempFileName, fileByte); FileInfo result = GetFileInfoFromPath(tempFileName); File.Delete(tempFileName); return(result); }
/// <summary> /// Add <c>From</c>. /// </summary> /// <param name="entityType"></param> /// <param name="id"></param> /// <returns><see cref="XrmEmail"/></returns> public XrmEmail From(FromEntityType entityType, Guid id) { ExceptionThrow.IfGuidEmpty(id, "From.Id"); if (string.IsNullOrEmpty(_from.Key) && _from.Value.IsGuidEmpty()) { _from = new KeyValuePair <string, Guid>(entityType.Description(), id); } else { throw new ArgumentException("You can only add one record FROM data. Please NULL to list before add new record"); } return(this); }
/// <summary> /// Convert <see cref="XrmEmail"/> to <see cref="Entity"/> for <c>Email Activity</c>. /// </summary> /// <returns><see cref="Entity"/></returns> public Entity ToEntity() { Entity result = null; if (!_isInit) { throw new InvalidOperationException("Please INIT (call constructor of XrmEmail) before call ToEntity method."); } ExceptionThrow.IfNullOrEmpty(_from.Key, "From.EntityType"); ExceptionThrow.IfGuidEmpty(_from.Value, "From.Id"); ExceptionThrow.IfNull(_to, "To"); ExceptionThrow.IfNullOrEmpty(_to.ToArray(), "To"); ExceptionThrow.IfNullOrEmpty(_subject, "Subject"); ExceptionThrow.IfNullOrEmpty(_body, "Body"); result = new Entity("email"); Entity from = new Entity("activityparty"); from["partyid"] = new EntityReference(_from.Key, _from.Value); result["subject"] = _subject; result["description"] = _body; result["from"] = new[] { from }; result["to"] = CreateActivityParty(_to); result["cc"] = CreateActivityParty(_cc); result["bcc"] = CreateActivityParty(_bcc); result["directioncode"] = _directionCode; result["prioritycode"] = new OptionSetValue(_priority); result["statuscode"] = new OptionSetValue(1); //INFO : In Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update, the Email.StatusCode attribute cannot be null. https://msdn.microsoft.com/en-us/library/gg334229.aspx if (!string.IsNullOrEmpty(_regardingObject.Key) && !_regardingObject.Value.IsGuidEmpty()) { result["regardingobjectid"] = new EntityReference(_regardingObject.Key, _regardingObject.Value); } if (_customAttributeList != null && _customAttributeList.Keys.Count > 0) { foreach (KeyValuePair <string, object> item in _customAttributeList) { result[item.Key] = item.Value; } } return(result); }
/// <summary> /// Retrieve <c>UtcTime</c> from <c>LocalTime</c> by specified <c>System User</c> 's settings. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.utctimefromlocaltimerequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="localTime"><see cref="DateTime"/> LocalTime</param> /// <param name="userId">Systemuser Id</param> /// <returns> /// <see cref="DateTime"/> UtcTime /// </returns> public DateTime GetUTCTimeFromLocalTime(DateTime localTime, Guid userId) { ExceptionThrow.IfGuidEmpty(userId, "userId"); var userSettings = GetCurrentUsersSettings(userId); UtcTimeFromLocalTimeRequest request = new UtcTimeFromLocalTimeRequest() { LocalTime = localTime, TimeZoneCode = userSettings.Item2 }; var serviceResponse = (UtcTimeFromLocalTimeResponse)this.OrganizationService.Execute(request); return(serviceResponse.UtcTime); }
void ValidateEntity(Entity entity) { ExceptionThrow.IfNull(entity, "Entity"); ExceptionThrow.IfNullOrEmpty(entity.LogicalName, "Entity.LogicalName"); var n = entity.LogicalName.ToLower().Trim(); if (n.Equals("phonecall") || n.Equals("appointment") || n.Equals("letter") || n.Equals("fax") || n.Equals("email")) { //Valid } else { ExceptionThrow.IfNotExpectedValue(entity.LogicalName, "Entity.LogicalName", "phonecall - appointment - letter - fax - email"); } }
/// <summary> /// Add a existing <c>Privilege</c> with name (<c>prv</c> prefix) to a <c>Role</c>. /// </summary> /// <param name="roleName">Role name</param> /// <param name="privilegeId"> /// <c>Privilege Id</c>. /// If you don't know <c>Privilege Id</c>, you can call <see cref="PrivilegeHelper.GetId(string)"/> method. /// </param> /// <param name="depth"><see cref="PrivilegeDepth"/></param> /// <returns><see cref="AddPrivilegesRoleResponse"/></returns> public AddPrivilegesRoleResponse AddPrivilege(string roleName, Guid privilegeId, PrivilegeDepth depth) { ExceptionThrow.IfGuidEmpty(privilegeId, "privilegeId"); ExceptionThrow.IfNullOrEmpty(roleName, "roleName"); Guid id = GetId(roleName); ExceptionThrow.IfGuidEmpty(id, "id", string.Format("'{0}' not found", roleName)); RolePrivilege privilege = new RolePrivilege() { Depth = depth, PrivilegeId = privilegeId }; return(AddPrivilege(id, privilege)); }
/// <summary> /// Remove link (association) between records. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.messages.disassociaterequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="mainRecordId"></param> /// <param name="mainRecordLogicalName"></param> /// <param name="relatedEntities"></param> /// <param name="relationName"></param> /// <returns> /// <see cref="DisassociateResponse"/> /// </returns> public DisassociateResponse Disassociate(Guid mainRecordId, string mainRecordLogicalName, EntityReferenceCollection relatedEntities, string relationName) { ExceptionThrow.IfGuidEmpty(mainRecordId, "mainRecordId"); ExceptionThrow.IfNullOrEmpty(mainRecordLogicalName, "mainRecordLogicalName"); ExceptionThrow.IfNull(relatedEntities, "relatedEntities"); ExceptionThrow.IfNullOrEmpty(relationName, "relationName"); DisassociateRequest request = new DisassociateRequest() { Target = new EntityReference(mainRecordLogicalName, mainRecordId), RelatedEntities = relatedEntities, Relationship = new Relationship(relationName) }; return((DisassociateResponse)this.OrganizationService.Execute(request)); }
/// <summary> /// Change <c>Invoice</c> status to <c>Cancelled</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.setstaterequest(v=crm.7).aspx /// </para> /// </summary> /// <param name="id"><c>Invoice</c> Id</param> /// <param name="status"><see cref="InvoiceCanceledStatusCode"/> status code</param> /// <param name="customStatusCode">If you're using your custom statuscodes set this, otherwise you can set "0 (zero)" or null</param> public void Canceled(Guid id, InvoiceCanceledStatusCode status, int customStatusCode = 0) { ExceptionThrow.IfGuidEmpty(id, "id"); int statusCode = (int)status; if (status == InvoiceCanceledStatusCode.CustomStatusCode) { ExceptionThrow.IfNegative(customStatusCode, "customStatusCode"); statusCode = customStatusCode; } CommonHelper commonHelper = new CommonHelper(this.OrganizationService); commonHelper.UpdateState(id, this.EntityName, 3, statusCode); }