Can't Win Quote when trying to convert Quote to Order using xRM SDK - entity not in correct state

Pertanyaan Can't Win Quote when trying to convert Quote to Order using xRM SDK - entity not in correct state

  • 07 Mei 2012 21:15
     
      Memiliki Kode

    I've been unable to convert Quotes to Orders using the xRM SDK. Here's my code:

    1 private static void ConvertQuoteToOrder(Microsoft.Xrm.Sdk.Client.OrganizationServiceContext context, Microsoft.Xrm.Sdk.Entity myQuote)
    2 {
    3 	Guid quoteId = myQuote.GetAttributeValue<Guid>("quoteid");
    4 
    5 	var quoteClose = new Entity("quoteclose");
    6 
    7 	quoteClose.Attributes["quoteid"] = myQuote.ToEntityReference();
    8 	quoteClose.Attributes["subject"] = "Won The Quote";
    9 
    10 	WinQuoteRequest winQuoteRequest = new WinQuoteRequest()
    11 	{
    12 		QuoteClose = quoteClose,
    13 		Status = new OptionSetValue(4)  //2?  -1??
    14 	};
    15 
    16 	var winQuoteResponse = (WinQuoteResponse)context.Execute(winQuoteRequest);
    17 
    18 	ColumnSet salesOrderColumns = new ColumnSet("salesorderid", "totalamount");
    19 
    20 	var convertOrderRequest = new ConvertQuoteToSalesOrderRequest()
    21 	{
    22 		QuoteId = quoteId,
    23 		ColumnSet = salesOrderColumns
    24 	};
    25 
    26 	var convertOrderResponse = (ConvertQuoteToSalesOrderResponse)context.Execute(convertOrderRequest);
    27 
    28 	var quote = convertOrderResponse.Entity;
    29 
    30 }

    When this code executes, I get the error on line 16 along the lines of "cannot close the entity because it is not in the correct state".

    Isn't that what the WinQuoteRequest is for?  I'm trying to put it in the correct state! Am I missing something?

Semua Balasan

  • 07 Mei 2012 20:31
     
      Memiliki Kode

    I've been unable to convert Quotes to Orders using the xRM SDK. Here's my code:

    1 private static void ConvertQuoteToOrder(Microsoft.Xrm.Sdk.Client.OrganizationServiceContext context, Microsoft.Xrm.Sdk.Entity myQuote)
    2 {
    3 	Guid quoteId = myQuote.GetAttributeValue<Guid>("quoteid");
    4 
    5 	var quoteClose = new Entity("quoteclose");
    6 
    7 	quoteClose.Attributes["quoteid"] = myQuote.ToEntityReference();
    8 	quoteClose.Attributes["subject"] = "Won The Quote";
    9 
    10 	WinQuoteRequest winQuoteRequest = new WinQuoteRequest()
    11 	{
    12 		QuoteClose = quoteClose,
    13 		Status = new OptionSetValue(4)  //2?  -1??
    14 	};
    15 
    16 	var winQuoteResponse = (WinQuoteResponse)context.Execute(winQuoteRequest);
    17 
    18 	ColumnSet salesOrderColumns = new ColumnSet("salesorderid", "totalamount");
    19 
    20 	var convertOrderRequest = new ConvertQuoteToSalesOrderRequest()
    21 	{
    22 		QuoteId = quoteId,
    23 		ColumnSet = salesOrderColumns
    24 	};
    25 
    26 	var convertOrderResponse = (ConvertQuoteToSalesOrderResponse)context.Execute(convertOrderRequest);
    27 
    28 	var quote = convertOrderResponse.Entity;
    29 
    30 }

    When this code executes, I get the error on line 16 along the lines of "cannot close the entity because it is not in the correct state".

    Isn't that what the WinQuoteRequest is for?  I'm trying to put it in the correct state! Am I missing something?

  • 08 Mei 2012 3:10
    Moderator
     
     

    Hello,

    Please don't create duplicated threads!


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

  • 08 Mei 2012 5:06
    Moderator
     
     

    What is the statecode and statuscode of the quote before your code executes ?

    It may be that you can only win a quote if it is already Active (statecode = 1, statuscode = 2,3 or 7). If so, and the quote isn't in that state, then you'd need to execute a SetStateRequest first


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk


  • 08 Mei 2012 16:31
     
     
    Sorry about that!

    I wasn't really sure which area this question belonged in.  I posted it in CRM first then noticed this area.
  • 08 Mei 2012 16:32
     
     
    The state is just the default state for a quote: Active  (statecode = 1).