/// <summary> /// Closes a quote as won or lost, /// Revise is not supported via this method /// </summary> /// <param name="quoteId">ID of the quote to close</param> /// <param name="fieldList">List of fields that need to be updated</param> /// <param name="quoteStatusCode">Status id of the quote, must be greater then 3 but not 7</param> /// <param name="batchId">Optional: if set to a valid GUID, generated by the Create Batch Request Method, will assigned the request to the batch for later execution, on fail, runs the request immediately </param> /// <param name="cdsServiceClient">Connected CDS Service Client</param> /// <param name="bypassPluginExecution">Adds the bypass plugin behavior to this request. Note: this will only apply if the caller has the prvBypassPlugins permission to bypass plugins. If its attempted without the permission the request will fault.</param> /// <returns></returns> public static Guid CloseQuote(this CdsServiceClient cdsServiceClient, Guid quoteId, Dictionary <string, CdsDataTypeWrapper> fieldList, int quoteStatusCode = 3, Guid batchId = default(Guid), bool bypassPluginExecution = false) { cdsServiceClient.logEntry.ResetLastError(); // Reset Last Error if (cdsServiceClient._CdsService == null) { cdsServiceClient.logEntry.Log("Crm Service not initialized", TraceEventType.Error); return(Guid.Empty); } if (quoteId == Guid.Empty) { return(Guid.Empty); } if (quoteStatusCode < 3) { return(Guid.Empty); } Guid actId = Guid.Empty; Entity uEnt = new Entity("quoteclose"); AttributeCollection PropertyList = new AttributeCollection(); #region MapCode if (fieldList != null) { foreach (KeyValuePair <string, CdsDataTypeWrapper> field in fieldList) { cdsServiceClient.AddValueToPropertyList(field, PropertyList); } } // Add the key... // check to see if the key is in the import set already if (fieldList != null && !fieldList.ContainsKey("quoteid")) { PropertyList.Add(new KeyValuePair <string, object>("quoteid", quoteId)); } if (fieldList != null && fieldList.ContainsKey("activityid")) { actId = (Guid)fieldList["activityid"].Value; } else { actId = Guid.NewGuid(); uEnt.Id = actId; } #endregion uEnt.Attributes.AddRange(PropertyList.ToArray()); // 2 types of close supported... Won or Lost. if (quoteStatusCode == 4) { WinQuoteRequest req = new WinQuoteRequest(); req.QuoteClose = uEnt; req.Status = new OptionSetValue(quoteStatusCode); if (cdsServiceClient.AddRequestToBatch(batchId, req, "Calling Close Quote as Won", "Request to Close Quote as Won Queued", bypassPluginExecution)) { return(Guid.Empty); } WinQuoteResponse resp = (WinQuoteResponse)cdsServiceClient.CdsCommand_Execute(req, "Closing a Quote in CRM as Won", bypassPluginExecution); if (resp != null) { return(actId); } else { return(Guid.Empty); } } else { CloseQuoteRequest req = new CloseQuoteRequest(); req.QuoteClose = uEnt; req.Status = new OptionSetValue(quoteStatusCode); if (cdsServiceClient.AddRequestToBatch(batchId, req, "Calling Close Quote as Lost", "Request to Close Quote as Lost Queued", bypassPluginExecution)) { return(Guid.Empty); } CloseQuoteResponse resp = (CloseQuoteResponse)cdsServiceClient.CdsCommand_Execute(req, "Closing a Quote in CRM as Lost", bypassPluginExecution); if (resp != null) { return(actId); } else { return(Guid.Empty); } } }
/// <summary> /// Cancel Sales order /// </summary> /// <param name="salesOrderId">Sales order id to close</param> /// <param name="fieldList">List of fields to add</param> /// <param name="orderStatusCode">Status code of the order</param> /// <param name="batchId">Optional: if set to a valid GUID, generated by the Create Batch Request Method, will assigned the request to the batch for later execution, on fail, runs the request immediately </param> /// <param name="cdsServiceClient">Connected CDS Service Client</param> /// <param name="bypassPluginExecution">Adds the bypass plugin behavior to this request. Note: this will only apply if the caller has the prvBypassPlugins permission to bypass plugins. If its attempted without the permission the request will fault.</param> /// <returns></returns> public static Guid CancelSalesOrder(this CdsServiceClient cdsServiceClient, Guid salesOrderId, Dictionary <string, CdsDataTypeWrapper> fieldList, int orderStatusCode = 4, Guid batchId = default(Guid), bool bypassPluginExecution = false) { cdsServiceClient.logEntry.ResetLastError(); // Reset Last Error if (cdsServiceClient._CdsService == null) { cdsServiceClient.logEntry.Log("Crm Service not initialized", TraceEventType.Error); return(Guid.Empty); } if (salesOrderId == Guid.Empty) { return(Guid.Empty); } if (orderStatusCode < 4) { return(Guid.Empty); } Guid actId = Guid.Empty; Entity uEnt = new Entity("orderclose"); AttributeCollection PropertyList = new AttributeCollection(); #region MapCode if (fieldList != null) { foreach (KeyValuePair <string, CdsDataTypeWrapper> field in fieldList) { cdsServiceClient.AddValueToPropertyList(field, PropertyList); } } // Add the key... // check to see if the key is in the import set allready if (fieldList != null && !fieldList.ContainsKey("salesorderid")) { PropertyList.Add(new KeyValuePair <string, object>("salesorderid", salesOrderId)); } if (fieldList != null && fieldList.ContainsKey("activityid")) { actId = (Guid)fieldList["activityid"].Value; } else { actId = Guid.NewGuid(); uEnt.Id = actId; } #endregion uEnt.Attributes.AddRange(PropertyList.ToArray()); CancelSalesOrderRequest req = new CancelSalesOrderRequest(); req.OrderClose = uEnt; req.Status = new OptionSetValue(orderStatusCode); if (cdsServiceClient.AddRequestToBatch(batchId, req, "Calling Close Sales Order", "Request to Close Sales Order Queued", bypassPluginExecution)) { return(Guid.Empty); } CancelSalesOrderResponse resp = (CancelSalesOrderResponse)cdsServiceClient.CdsCommand_Execute(req, "Closing a Sales Order in CRM as Closed", bypassPluginExecution); if (resp != null) { return(actId); } else { return(Guid.Empty); } }
/// <summary> /// Closes an Incident request in CRM, /// this special handling is necessary to support CRM Built In Object. /// </summary> /// <param name="incidentId">ID of the CRM Incident to close</param> /// <param name="fieldList">List of data items to add to the request, By default, subject is required.</param> /// <param name="incidentStatusCode">Status code to close the incident with, defaults to resolved</param> /// <param name="batchId">Optional: if set to a valid GUID, generated by the Create Batch Request Method, will assigned the request to the batch for later execution, on fail, runs the request immediately </param> /// <returns>Guid of the Activity.</returns> public static Guid CloseIncident(this CdsServiceClient cdsServiceClient, Guid incidentId, Dictionary <string, CdsDataTypeWrapper> fieldList, int incidentStatusCode = 5, Guid batchId = default(Guid)) { cdsServiceClient.logEntry.ResetLastError(); // Reset Last Error if (cdsServiceClient._CdsService == null) { cdsServiceClient.logEntry.Log("Crm Service not initialized", TraceEventType.Error); return(Guid.Empty); } if (incidentId == Guid.Empty) { return(Guid.Empty); } Guid actId = Guid.Empty; Entity uEnt = new Entity("incidentresolution"); AttributeCollection PropertyList = new AttributeCollection(); #region MapCode if (fieldList != null) { foreach (KeyValuePair <string, CdsDataTypeWrapper> field in fieldList) { cdsServiceClient.AddValueToPropertyList(field, PropertyList); } } // Add the key... // check to see if the key is in the import set already if (fieldList != null && !fieldList.ContainsKey("incidentid")) { PropertyList.Add(new KeyValuePair <string, object>("incidentid", new EntityReference("incident", incidentId))); } if (fieldList != null && fieldList.ContainsKey("activityid")) { actId = (Guid)fieldList["activityid"].Value; } else { actId = Guid.NewGuid(); uEnt.Id = actId; } #endregion uEnt.Attributes.AddRange(PropertyList.ToArray()); CloseIncidentRequest req4 = new CloseIncidentRequest(); req4.IncidentResolution = uEnt; req4.Status = new OptionSetValue(incidentStatusCode); if (cdsServiceClient.AddRequestToBatch(batchId, req4, "Calling Close Incident", "Request to Close Incident Queued")) { return(Guid.Empty); } CloseIncidentResponse resp4 = (CloseIncidentResponse)cdsServiceClient.CdsCommand_Execute(req4, "Closing a incidentId in CRM"); if (resp4 != null) { return(actId); } else { return(Guid.Empty); } }