0
votes

I am trying to close a quote in MSCRM using C# CloseQuoteRequest.

CloseQuoteRequest closeQuoteRequest = new CloseQuoteRequest()
{
    QuoteClose = new QuoteClose()
    {
        QuoteId = quote.ToEntityReference(),
        Subject = "Quote Close " + DateTime.Now.ToString(),
    },
    Status = new OptionSetValue(-1),
    RequestName = "CloseQuote",
};
Service.Execute(closeQuoteRequest);

I am getting the error;

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException message was 'Error in line 1 position 711. Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'CRM.Entities.Entities:QuoteClose'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'QuoteClose' and namespace 'CRM.Entities.Entities'.'. Please see InnerException for more details.

There is no inner exception for me to see.

3
Try not setting the RequestName property. I haven't tried it, but the documentation says this is "required, but is supplied by derived classes.(Inherited from OrganizationRequest.)"jasonscript

3 Answers

0
votes

Code sample from MSDN don’t have RequestName = "CloseQuote" property being set as it’s not needed. Remove it.

// Close the quote
CloseQuoteRequest closeQuoteRequest = new CloseQuoteRequest()
{
    QuoteClose = new QuoteClose()
    {
        QuoteId = closeQuote.ToEntityReference(),
        Subject = "Quote Close " + DateTime.Now.ToString()
    },
    Status = new OptionSetValue(-1)
};
_serviceProxy.Execute(closeQuoteRequest);

RequestName
Gets or sets the name of the request. Required, but is supplied by derived classes.(Inherited from OrganizationRequest.)

Status
The Status property corresponds to the Quote.StatusCode attribute. It is shown as “Status Reason” in the Microsoft Dynamics 365 application. If you set the value of this property to -1, the system sets the appropriate corresponding status value.

0
votes

I don't know why this was the case but adding .ToEntity() to the QuoteClose Entity worked.

CloseQuoteRequest closeQuoteRequest = new CloseQuoteRequest()
{
    QuoteClose = new QuoteClose()
    {
        QuoteId = quote.ToEntityReference(),
        Subject = "Quote Close " + DateTime.Now.ToString(),
    }.ToEntity<Entity>(),
    Status = new OptionSetValue(-1),
    RequestName = "CloseQuote",
};
Service.Execute(closeQuoteRequest);
0
votes
WinQuoteRequest winQuoteRequest = new WinQuoteRequest();
Entity wonQuoteClose = new Entity("quoteclose");
wonQuoteClose.Attributes["quoteid"] = new EntityReference("quote", id);
wonQuoteClose.Attributes["subject"] = "Quote Close" + DateTime.Now.ToString();
winQuoteRequest.QuoteClose = wonQuoteClose;
winQuoteRequest.Status = new OptionSetValue(-1);
service.Execute(winQuoteRequest);