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

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

  • 2012. május 7. 21:15
     
      Kódot tartalmaz

    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?

Az összes válasz

  • 2012. május 7. 20:31
     
      Kódot tartalmaz

    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?

  • 2012. május 8. 3:10
    Moderátor
     
     

    Hello,

    Please don't create duplicated threads!


    Microsoft CRM Freelancer

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

  • 2012. május 8. 5:06
    Moderátor
     
     

    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


  • 2012. május 8. 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.
  • 2012. május 8. 16:32
     
     
    The state is just the default state for a quote: Active  (statecode = 1).