/// <summary> /// Add <c>location</c> /// </summary> /// <param name="location">Location</param> /// <returns><see cref="XrmAppointment"/></returns> public XrmAppointment Location(string location) { ExceptionThrow.IfNullOrEmpty(location, "location"); _location = location.Trim(); return(this); }
/// <summary> /// Add <c>description</c> /// </summary> /// <param name="description">Description</param> /// <returns><see cref="XrmAppointment"/></returns> public XrmAppointment Description(string description) { ExceptionThrow.IfNullOrEmpty(description, "description"); _description = description.Trim(); return(this); }
/// <summary> /// Add <c>subject</c> /// </summary> /// <param name="subject">Subject</param> /// <returns><see cref="XrmAppointment"/></returns> public XrmAppointment Subject(string subject) { ExceptionThrow.IfNullOrEmpty(subject, "subject"); _subject = subject.Trim(); return(this); }
/// <summary> /// Create an <see cref="AttachmentData"/> from <c>path</c>. /// </summary> /// <param name="path">File full path (with <c>drive\folder\filename.extension</c>)</param> /// <param name="fileName">If you want override filename on CRM please provide that. Otherwise leave blank.</param> /// <returns> /// <see cref="AttachmentData"/> /// </returns> public static AttachmentData CreateFromPath(string path, string fileName) { ExceptionThrow.IfNullOrEmpty(path, "path"); ExceptionThrow.IfFileNotFound(path, "path"); FileInfo fileInfo = new FileInfo(path); byte[] fileByte = File.ReadAllBytes(path); AttachmentData result = new AttachmentData() { Data = new AttachmentFileData() { Base64 = fileByte.ToBase64String(), ByteArray = fileByte }, Meta = new AttachmentFileMeta { Directory = fileInfo.Directory.FullName, Extension = fileInfo.Extension, FullPath = fileInfo.FullName, MimeType = MimeMapping.GetMimeMapping(fileInfo.Name), Name = !string.IsNullOrEmpty(fileName) ? fileName : fileInfo.Name, Size = fileByte.Length } }; return(result); }
/// <summary> /// Send an <c>Email</c> message using a <c>Template</c>. /// If you do not know your template id, you can use this method with just template title. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.sendemailfromtemplaterequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="email">CRM (XRM) email entity without body and subject. Email body and subject will be replaced by specified template's properties.</param> /// <param name="templateTitle"><c>Template</c> title</param> /// <param name="regarding">Regarding object that related by template</param> /// <returns>Created record Id (<see cref="Guid"/>)</returns> public Guid Send(Entity email, string templateTitle, EntityReference regarding) { ExceptionThrow.IfNullOrEmpty(templateTitle, "templateTitle"); ExceptionThrow.IfNull(regarding, "regarding"); ExceptionThrow.IfGuidEmpty(regarding.Id, "EntityReference.Id"); ExceptionThrow.IfNullOrEmpty(regarding.LogicalName, "EntityReference.LogicalName"); ValidateEmailEntity(email); QueryExpression query = new QueryExpression("template") { ColumnSet = new ColumnSet("templateid", "templatetypecode"), Criteria = new FilterExpression() }; query.Criteria.AddCondition("title", ConditionOperator.Equal, templateTitle); query.Criteria.AddCondition("templatetypecode", ConditionOperator.Equal, regarding.LogicalName.ToLower()); EntityCollection templateCollection = this.OrganizationService.RetrieveMultiple(query); ExceptionThrow.IfNull(templateCollection, "template", string.Format("'{0}' template not exists or not related with '{1}' entity.", templateTitle, regarding.LogicalName)); ExceptionThrow.IfGreaterThan(templateCollection.Entities.Count, "template", 1, "There are more than one template with same name"); Guid templateId = templateCollection.Entities[0].Id; return(Send(email, templateId, regarding)); }
/// <summary> /// Search for <c>Knowledge Article</c>. /// <para> /// For more information look at /// <c>By Fulltext</c> : https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.fulltextsearchknowledgearticlerequest.aspx /// </para> /// </summary> /// <param name="searchType"><see cref="SearchTypeCode"/></param> /// <param name="query"> /// Query criteria to find <c>Knowledge Article</c> with specified keyword. /// This parameter supports <c>QueryExpression</c> and <c>FetchXml</c>. /// <para> /// Please note that <see cref="PagingInfo"/> data must be defined in this query. /// </para> /// </param> /// <param name="searchText">Text to search for in <c>Knowledge Article</c> data</param> /// <param name="useInflection">Indicates whether to use inflectional stem matching when searching for knowledge base articles with a specified body text</param> /// <param name="removeDuplicates"> /// Indicates whether to remove multiple versions of the same knowledge article in search results. /// Default value is <c>true</c>. /// </param> /// <param name="stateCode"> /// State of the knowledge articles to filter the search results. /// Default value is <c>-1</c> (for all data). For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.fulltextsearchknowledgearticlerequest.statecode.aspx /// </param> /// <returns> /// <see cref="EntityCollection"/> for <c>Article</c> data. /// </returns> public EntityCollection Search(SearchTypeCode searchType, QueryBase query, string searchText, bool useInflection, bool removeDuplicates = true, int stateCode = -1) { ExceptionThrow.IfNull(query, "query"); ExceptionThrow.IfNullOrEmpty(searchText, "searchText"); if (query is QueryExpression) { ExceptionThrow.IfNullOrEmpty(((QueryExpression)query).EntityName, "QueryExpression.EntityName"); ExceptionThrow.IfNotExpectedValue(((QueryExpression)query).EntityName.ToLower(), "QueryExpression.EntityName", this.EntityName.ToLower()); } EntityCollection result = new EntityCollection(); OrganizationRequest serviceRequest = null; OrganizationResponse serviceResponse = null; switch (searchType) { case SearchTypeCode.FullText: serviceRequest = new FullTextSearchKnowledgeArticleRequest() { QueryExpression = query, RemoveDuplicates = removeDuplicates, SearchText = searchText, StateCode = stateCode, UseInflection = useInflection }; serviceResponse = this.OrganizationService.Execute(serviceRequest); result = ((FullTextSearchKnowledgeArticleResponse)serviceResponse).EntityCollection; break; } return(result); }
/// <summary> /// Retrieve <c>Transaction Currency</c> information for specified entity. /// </summary> /// <param name="id"></param> /// <param name="entityLogicalName"></param> /// <returns></returns> public EntityReference GetTransactionCurrencyInfo(Guid id, string entityLogicalName) { ExceptionThrow.IfGuidEmpty(id, "id"); ExceptionThrow.IfNullOrEmpty(entityLogicalName, "entityLogicalName"); EntityReference result = null; var transactionCurrency = this.OrganizationService.Retrieve(entityLogicalName, id, new ColumnSet("transactioncurrencyid")); if (transactionCurrency != null && transactionCurrency.Contains("transactioncurrencyid")) { result = (EntityReference)transactionCurrency["transactioncurrencyid"]; } else { QueryExpression organizationQuery = new QueryExpression("organization") { ColumnSet = new ColumnSet("basecurrencyid") }; var response = this.OrganizationService.RetrieveMultiple(organizationQuery); if (response != null && response.Entities != null && response.Entities.Count > 0) { result = (EntityReference)response.Entities[0]["basecurrencyid"]; } } return(result); }
/// <summary> /// Retrieve <see cref="FileInfo"/> data from <c>path</c>. /// </summary> /// <param name="path"></param> /// <returns> /// <see cref="FileInfo"/> /// </returns> public static FileInfo GetFileInfoFromPath(string path) { ExceptionThrow.IfNullOrEmpty(path, "path"); ExceptionThrow.IfFileNotFound(path, "path"); return(new FileInfo(path)); }
/// <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="privilegeName">Privilege name with <c>prv</c> prefix</param> /// <param name="depth"><see cref="PrivilegeDepth"/></param> /// <returns><see cref="AddPrivilegesRoleResponse"/></returns> public AddPrivilegesRoleResponse AddPrivilege(string roleName, string privilegeName, PrivilegeDepth depth) { ExceptionThrow.IfNullOrEmpty(privilegeName, "privilegeName"); ExceptionThrow.IfNullOrEmpty(roleName, "roleName"); Guid id = GetId(roleName); ExceptionThrow.IfGuidEmpty(id, "id", string.Format("'{0}' not found", roleName)); PrivilegeHelper privilegeHelper = new PrivilegeHelper(this.OrganizationService); var privilegeList = privilegeHelper.GetPredefinedPrivileges(); ExceptionThrow.IfNull(privilegeList, "privilegeList", "System pre-defined privileges not found (001)"); ExceptionThrow.IfNullOrEmpty(privilegeList.Entities, "privilegeList.Entities", "System pre-defined privileges not found (002)"); var existingRole = privilegeList.Entities.Where(d => d["name"].Equals(privilegeName)).SingleOrDefault(); ExceptionThrow.IfNull(existingRole, "Privilege", string.Format("'{0}' privilege not found", privilegeName)); RolePrivilege privilege = new RolePrivilege() { Depth = depth, PrivilegeId = existingRole.Id }; return(AddPrivilege(id, privilege)); }
/// <summary> /// Validates the state transition. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.isvalidstatetransitionrequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="recordId">Record Id</param> /// <param name="entityLogicalName">Record's entity logical name</param> /// <param name="newStateCode"></param> /// <param name="newStatusCode"></param> /// <returns> /// Returns <c>true</c> if is valid. (<see cref="IsValidStateTransitionResponse.IsValid"/>) /// </returns> public bool Validate(Guid recordId, string entityLogicalName, string newStateCode, int newStatusCode) { ExceptionThrow.IfGuidEmpty(recordId, "id"); ExceptionThrow.IfNullOrEmpty(entityLogicalName, "entityLogicalName"); List <string> supportedEntityList = new List <string>() { "incident", "msdyn_postalbum", "msdyn_postconfig", "msdyn_postruleconfig", "msdyn_wallsavedquery", "msdyn_wallsavedqueryusersettings", "opportunity" }; if (!supportedEntityList.Contains(entityLogicalName.ToLower().Trim())) { ExceptionThrow.IfNotExpectedValue(entityLogicalName, "entityLogicalName", "", string.Format("{0} is not supported for this operation. For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.isvalidstatetransitionrequest(v=crm.8).aspx", entityLogicalName)); } IsValidStateTransitionRequest request = new IsValidStateTransitionRequest() { Entity = new EntityReference(entityLogicalName, recordId), NewState = newStateCode.Trim(), NewStatus = newStatusCode }; IsValidStateTransitionResponse response = (IsValidStateTransitionResponse)this.OrganizationService.Execute(request); return(response.IsValid); }
/// <summary> /// Distribute <c>CampaignActivity</c> with <c>Email</c> activity. /// </summary> /// <param name="id"><c>CampaignActvity</c> Id</param> /// <param name="fromType">Email <c>From</c> (<see cref="FromEntityType"/>)</param> /// <param name="fromId">Email <c>From</c> Id</param> /// <param name="subject">Email Subject</param> /// <param name="body">Email Body</param> /// <param name="emailTemplateId"> /// If you want to use existing <c>template</c> set this field. /// Method throws an exception (<see cref="ExceptionThrow.IfGuidEmpty(Guid, string, string)"/>) if you set this field to <see cref="Guid.Empty"/> /// </param> /// <param name="sendEmail"> /// Set <c>true</c> if you want to send created activities. /// </param> /// <param name="propagationOwnershipOptions"></param> /// <param name="ownerTypeCode"></param> /// <param name="ownerId"></param> /// <param name="queueId"></param> /// <param name="doesPropagate">Set <c>true</c>, whether the activity is both created and executed. Otherwise set <c>false</c>.</param> /// <param name="useAsync"> /// Set <c>true</c>, whether the activity is both created and executed. Otherwise set <c>false</c>. /// This field's default value is <c>true</c>, so activity will be created and executed (exp: email wil be send) /// </param> /// <param name="validateActivity"></param> /// <returns> /// Returns created <c>BulkOperation</c> Id in <see cref="DistributeCampaignActivityResponse.BulkOperationId"/> property. /// </returns> public DistributeCampaignActivityResponse DistributeByEmail(Guid id, FromEntityType fromType, Guid fromId, string subject, string body, Guid?emailTemplateId, bool sendEmail, PropagationOwnershipOptions propagationOwnershipOptions, PrincipalType ownerTypeCode, Guid ownerId, Guid?queueId, bool doesPropagate = true, bool useAsync = true, bool validateActivity = true) { ExceptionThrow.IfGuidEmpty(fromId, "fromId"); Entity from = new Entity("activityparty"); from["partyid"] = new EntityReference(fromType.Description(), fromId); Entity entity = new Entity("email"); entity["from"] = new[] { from }; if (emailTemplateId.HasValue) { ExceptionThrow.IfGuidEmpty(emailTemplateId.Value, "templateId"); } else { ExceptionThrow.IfNullOrEmpty(subject, "subject"); ExceptionThrow.IfNullOrEmpty(body, "body"); entity["subject"] = subject; entity["description"] = body; } return(Distribute(id, entity, propagationOwnershipOptions, ownerTypeCode, ownerId, queueId, emailTemplateId, doesPropagate, useAsync, sendEmail, validateActivity)); }
/// <summary> /// Create an <see cref="AttachmentData"/> from <c>Base64</c> content. /// </summary> /// <param name="content"><c>Base64</c> content</param> /// <param name="fileName"></param> /// <returns> /// <see cref="AttachmentData"/> /// </returns> public static AttachmentData CreateFromBase64(string content, string fileName) { ExceptionThrow.IfNullOrEmpty(content, "content"); ExceptionThrow.IfNullOrEmpty(fileName, "fileName"); string tempFileName = Path.GetTempFileName(); byte[] fileByte = Convert.FromBase64String(content); File.WriteAllBytes(tempFileName, fileByte); FileInfo fileInfo = new FileInfo(tempFileName); AttachmentData result = new AttachmentData() { Data = new AttachmentFileData() { Base64 = fileByte.ToBase64String(), ByteArray = fileByte }, Meta = new AttachmentFileMeta { Directory = fileInfo.Directory.FullName, Extension = fileInfo.Extension, FullPath = fileInfo.FullName, MimeType = MimeMapping.GetMimeMapping(fileInfo.Name), Name = !string.IsNullOrEmpty(fileName) ? fileName : fileInfo.Name, Size = fileByte.Length } }; File.Delete(tempFileName); return(result); }
/// <summary> /// Create a <c>Campaign Activity</c>. /// </summary> /// <param name="campaignId"><c>Campaign</c> Id</param> /// <param name="subject">Subject</param> /// <param name="description">Description</param> /// <param name="typeCode"><see cref="CampaignActivityTypeCode"/> type code</param> /// <param name="channelCode"><see cref="CampaignActivityChannelTypeCode"/> channel code</param> /// <param name="customTypeCode">If you're using your custom typecode set this, otherwise you can set "0 (zero)" or null</param> /// <param name="customChannelCode">If you're using your custom channel code set this, otherwise you can set "0 (zero)" or null</param> /// <returns> /// Created record Id (<see cref="Guid"/>) /// </returns> public Guid Create(Guid campaignId, string subject, string description, CampaignActivityTypeCode typeCode, CampaignActivityChannelTypeCode channelCode, int customTypeCode = 0, int customChannelCode = 0) { ExceptionThrow.IfGuidEmpty(campaignId, "campaignId"); ExceptionThrow.IfNullOrEmpty(subject, "subject"); int activityTypeCode = (int)typeCode; int activityChannelCode = (int)channelCode; if (typeCode == CampaignActivityTypeCode.CustomTypeCode) { ExceptionThrow.IfNegative(customTypeCode, "customTypeCode"); activityTypeCode = customTypeCode; } if (channelCode == CampaignActivityChannelTypeCode.CustomChannelTypeCode) { ExceptionThrow.IfNegative(customChannelCode, "customChannelCode"); activityChannelCode = customChannelCode; } Entity entity = new Entity(this.EntityName); entity["regardingobjectid"] = new EntityReference("campaign", campaignId); entity["subject"] = subject; entity["typecode"] = new OptionSetValue(activityTypeCode); entity["channeltypecode"] = new OptionSetValue(activityChannelCode); entity["description"] = description; return(this.OrganizationService.Create(entity)); }
/// <summary> /// Add a <c>Contract Detail</c> to <c>Contract</c> with basic data. /// <c>Customer</c>, <c>Start Date</c> and <c>End Date</c> properties will be copied from <c>Contract</c> data. /// </summary> /// <param name="contractId"><c>Contract</c> Id</param> /// <param name="title">Title (description) of contract line</param> /// <param name="totalPrice">Total Price</param> /// <param name="totalAllotments">Total number of <c>minutes</c> or <c>case (incident)</c> allowed for the contract line.</param> /// <returns>Created record Id (<see cref="System.Guid"/>)</returns> public Guid Add(Guid contractId, string title, decimal totalPrice, int totalAllotments) { ExceptionThrow.IfGuidEmpty(contractId, "contractId"); ExceptionThrow.IfNullOrEmpty(title, "title"); ContractHelper contractHelper = new ContractHelper(this.OrganizationService); var contract = contractHelper.Get(contractId, "customerid", "activeon", "expireson"); ExceptionThrow.IfNull(contract, "contract", string.Format("'{0}' not found", contractId)); ExceptionThrow.IfNull(contract.GetAttributeValue <EntityReference>("customerid"), "contract.CustomerId"); ExceptionThrow.IfGuidEmpty(contract.GetAttributeValue <EntityReference>("customerid").Id, "contract.CustomerId"); ExceptionThrow.IfEquals(contract.GetAttributeValue <DateTime>("activeon"), "contract.StartDate", DateTime.MinValue); ExceptionThrow.IfEquals(contract.GetAttributeValue <DateTime>("expireson"), "contract.EndDate", DateTime.MinValue); Entity entity = new Entity(this.EntityName); entity["contractid"] = new EntityReference("contract", contractId); entity["title"] = title; entity["customerid"] = contract.GetAttributeValue <EntityReference>("customerid"); entity["activeon"] = contract.GetAttributeValue <DateTime>("activeon"); entity["expireson"] = contract.GetAttributeValue <DateTime>("expireson"); entity["price"] = new Money(totalPrice); entity["totalallotments"] = totalAllotments; return(this.OrganizationService.Create(entity)); }
/// <summary> /// Delete an existing record /// </summary> /// <param name="id">Record Id</param> /// <param name="entityLogicalName">Record logical name</param> public void Delete(Guid id, string entityLogicalName) { ExceptionThrow.IfGuidEmpty(id, "id"); ExceptionThrow.IfNullOrEmpty(entityLogicalName, "entityLogicalName"); this.OrganizationService.Delete(entityLogicalName, id); }
/// <summary> /// Retrieve records by specified <c>FetchXml</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.query.fetchexpression(v=crm.7).aspx /// </para> /// </summary> /// <param name="fetchxml"><c>FetchXml</c></param> /// <returns> /// <see cref="EntityCollection"/> for data /// </returns> public EntityCollection Get(string fetchxml) { ExceptionThrow.IfNullOrEmpty(fetchxml, "fetchxml"); FetchExpression request = new FetchExpression(fetchxml); return(this.OrganizationService.RetrieveMultiple(request)); }
/// <summary> /// Add additional attribute /// </summary> /// <param name="attributeName">Attribute name</param> /// <param name="value"> /// Attribute value by MS CRM datatypes (<see cref="String"/>, <see cref="int"/> or <see cref="EntityReference"/>, <see cref="OptionSetValue"/>) /// </param> /// <returns> /// <see cref="XrmEmail"/> /// </returns> public XrmEmail AddCustomAttribute(string attributeName, object value) { ExceptionThrow.IfNullOrEmpty(attributeName, "attributeName"); _customAttributeList.Add(attributeName, value); return(this); }
/// <summary> /// Add <c>Body</c>. /// </summary> /// <param name="body"></param> /// <returns><see cref="XrmEmail"/></returns> public XrmEmail Body(string body) { ExceptionThrow.IfNullOrEmpty(body, "body"); _body = body.Trim(); return(this); }
/// <summary> /// Add <c>BCC</c> with email address. /// </summary> /// <param name="emailAddress"></param> /// <returns><see cref="XrmEmail"/></returns> public XrmEmail Bcc(string emailAddress) { ExceptionThrow.IfNullOrEmpty(emailAddress, "BCC EmailAddress"); _bcc.Add(new Tuple <ToEntityType, Guid, string>(ToEntityType.Undefined, Guid.Empty, emailAddress)); return(this); }
/// <summary> /// Create an attachment from <see cref="Stream"/>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/gg328344(v=crm.7).aspx /// </para> /// </summary> /// <param name="emailId">Existing <c>Email Activity</c> Id</param> /// <param name="stream">File content</param> /// <param name="fileName">This will be attachment name</param> /// <returns>Created record Id (<see cref="System.Guid"/>)</returns> public Guid Attach(Guid emailId, Stream stream, string fileName) { ExceptionThrow.IfGuidEmpty(emailId, "emailId"); ExceptionThrow.IfNull(stream, "stream"); ExceptionThrow.IfNullOrEmpty(fileName, "fileName"); return(Attach(emailId, stream.ToByteArray(), fileName)); }
/// <summary> /// Create an attachment from drive path. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/gg328344(v=crm.7).aspx /// </para> /// </summary> /// <param name="emailId"><c>Email Activity</c> Id</param> /// <param name="path">File path</param> /// <returns> /// Created record Id (<see cref="System.Guid"/>) /// </returns> public Guid Attach(Guid emailId, string path) { ExceptionThrow.IfGuidEmpty(emailId, "emailId"); ExceptionThrow.IfNullOrEmpty(path, "path"); var attachment = AttachmentHelper.CreateFromPath(path, string.Empty); return(Attach(emailId, attachment.Data.ByteArray, attachment.Meta.Name)); }
/// <summary> /// Enable a <c>System User</c> by domainname. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/jj602914(v=crm.8).aspx /// </para> /// </summary> /// <param name="domainname"><c>Active Directory name</c>(with domain)</param> public void Enable(string domainname) { ExceptionThrow.IfNullOrEmpty(domainname, "domainname"); Guid id = GetId(domainname.Trim()); ExceptionThrow.IfGuidEmpty(id, "id", string.Format("{0} user not found", domainname)); Enable(id); }
/// <summary> /// Retrieve record by Id /// </summary> /// <param name="id">Record (Entity) Id</param> /// <param name="retrievedColumns">Set columns (attributes) that you need. If you don't set, default value is <see cref="ColumnSet(true)"/></param> /// <returns> /// <see cref="Entity"/> for record data /// </returns> public Entity Get(Guid id, params string[] retrievedColumns) { ExceptionThrow.IfNullOrEmpty(this.EntityName, "BaseEntityHelper.EntityName"); ExceptionThrow.IfGuidEmpty(id, "id"); var columnSet = !retrievedColumns.IsNullOrEmpty() ? new ColumnSet(retrievedColumns) : new ColumnSet(true); return(this.OrganizationService.Retrieve(this.EntityName.ToLower().Trim(), id, columnSet)); }
/// <summary> /// Delete an existing record /// </summary> /// <param name="id">Record Id</param> public void Delete(Guid id) { ExceptionThrow.IfNullOrEmpty(this.EntityName, "BaseEntityHelper.EntityName"); ExceptionThrow.IfGuidEmpty(id, "id"); CommonHelper commonHelper = new CommonHelper(this.OrganizationService); commonHelper.Delete(id, this.EntityName); }
/// <summary> /// Remove attribute if exists /// </summary> /// <param name="entity"></param> /// <param name="node"></param> void RemoveAttribute(ref Entity entity, string node) { ExceptionThrow.IfNull(entity, "entity"); ExceptionThrow.IfNullOrEmpty(node, "node"); if (entity.Contains(node)) { entity.Attributes.Remove(node); } }
/// <summary> /// Distribute <c>CampaignActivity</c> with <c>Phonecall</c> activity. /// </summary> /// <param name="id"><c>CampaignActvity</c> Id</param> /// <param name="subject">Phonecall Subject</param> /// <param name="propagationOwnershipOptions"> /// <c>Ownership</c> options for the activity /// This parameter 's values are; /// <c>Caller</c> : All created activities are assigned to the caller of <see cref="IOrganizationService"/> /// <c>ListMemberOwner</c> : Created activities are assigned to respective owners of target members. /// <c>None</c> : There is no change in ownership for the created activities. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.propagationownershipoptions(v=crm.8).aspx /// </para> /// </param> /// <param name="ownerTypeCode"></param> /// <param name="ownerId"></param> /// <param name="queueId"> /// Set this field if you want also add created activities to an <c>Queue</c>. /// Method throws an exception (<see cref="ExceptionThrow.IfGuidEmpty(Guid, string, string)"/>) if you set this field to <see cref="Guid.Empty"/> /// </param> /// <param name="doesPropagate">Set <c>true</c>, whether the activity is both created and executed. Otherwise set <c>false</c>.</param> /// <param name="useAsync"> /// Set <c>true</c>, if you want use an asynchronous job to distribute activities. Otherwise set <c>false</c>. /// This field's default value is <c>true</c> /// </param> /// <param name="validateActivity"> /// Validates activity entity with required attributes and using method's enum values /// </param> /// <returns> /// Returns created <c>BulkOperation</c> Id in <see cref="DistributeCampaignActivityResponse.BulkOperationId"/> property. /// </returns> public DistributeCampaignActivityResponse DistributeByPhonecall(Guid id, string subject, PropagationOwnershipOptions propagationOwnershipOptions, PrincipalType ownerTypeCode, Guid ownerId, Guid?queueId, bool doesPropagate = true, bool useAsync = true, bool validateActivity = true) { ExceptionThrow.IfNullOrEmpty(subject, "subject"); Entity entity = new Entity("phonecall"); entity["subject"] = subject; return(Distribute(id, entity, propagationOwnershipOptions, ownerTypeCode, ownerId, queueId, null, doesPropagate, useAsync, false, validateActivity)); }
/// <summary> /// Create an <c>Annotation</c>. /// </summary> /// <param name="relatedObject">Related object that attach note</param> /// <param name="subject">Subject</param> /// <param name="text">Note text</param> /// <returns>Created record Id (<see cref="Guid"/>)</returns> public Guid Create(EntityReference relatedObject, string subject, string text) { ExceptionThrow.IfNull(relatedObject, "relatedObject"); ExceptionThrow.IfGuidEmpty(relatedObject.Id, "relatedObject.Id"); ExceptionThrow.IfNullOrEmpty(relatedObject.LogicalName, "relatedObject.LogicalName"); ExceptionThrow.IfNullOrEmpty(text, "text"); Entity entity = PrepareBasicAnnotation(relatedObject, subject, text); return(this.OrganizationService.Create(entity)); }
/// <summary> /// Add a <c>Quote product</c> to <c>Quote</c> with manual product information. /// </summary> /// <param name="quoteId"><c>Quote</c> Id</param> /// <param name="productName"><c>Product Name</c></param> /// <param name="quantity"><c>Quantity</c></param> /// <param name="price"><c>Price</c></param> /// <param name="discountAmount"><c>Discount amount</c> by currency</param> /// <param name="tax"><c>Tax amount</c>by currency</param> /// <returns>Created record Id (<see cref="Guid"/>)</returns> public Guid Add(Guid quoteId, string productName, decimal quantity, decimal price, decimal?discountAmount, decimal?tax) { ExceptionThrow.IfGuidEmpty(quoteId, "quoteId"); ExceptionThrow.IfNullOrEmpty(productName, "productName"); ExceptionThrow.IfNegative(quantity, "quantity"); ExceptionThrow.IfNegative(price, "price"); var entity = XProduct.Create(this.EntityName, "quote", quoteId, null, null, productName, quantity, price, discountAmount, tax); return(this.OrganizationService.Create(entity)); }
/// <summary> /// Create an attachment from byte array. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/gg328344(v=crm.7).aspx /// </para> /// </summary> /// <param name="emailId"><c>Email Activity</c> Id</param> /// <param name="content">File content</param> /// <param name="fileName">This will be attachment name</param> /// <returns> /// Created record Id (<see cref="System.Guid"/>) /// </returns> public Guid Attach(Guid emailId, byte[] content, string fileName) { ExceptionThrow.IfGuidEmpty(emailId, "emailId"); ExceptionThrow.IfNull(content, "content"); ExceptionThrow.IfNegative(content.Length, "content"); ExceptionThrow.IfNullOrEmpty(fileName, "fileName"); var entity = PrepareAttachmentData(emailId, content, fileName); return(this.OrganizationService.Create(entity)); }
/// <summary> /// Update marketing list name (<c>listname</c> attribute). /// </summary> /// <param name="id"></param> /// <param name="name"></param> void UpdateName(Guid id, string name) { ExceptionThrow.IfGuidEmpty(id, "id"); ExceptionThrow.IfNullOrEmpty(name, "name"); Entity entity = new Entity(this.EntityName); entity["listid"] = id; entity["listname"] = name; this.OrganizationService.Update(entity); }