locked
Clone quote using SDK RRS feed

  • Question

  • Hi,

    I'm trying to develop a module to clone quotations, so far I have this but it always throws an exception "Server was unable to process request"

    CrmService service = CRMService.GetServiceReference();
    quote oldQuote = (quote)service.Retrieve(EntityName.quote.ToString(), new Guid(Request.QueryString["id"]), new AllColumns());
    quote newQuote = oldQuote;
    service.Create(newQuote); // exception thrown here

    What do I need to do with newQuote to enable it to save?

    Thanks

     

    Friday, January 14, 2011 12:55 AM

Answers

  • Hi,

    I'm trying to develop a module to clone quotations, so far I have this but it always throws an exception "Server was unable to process request"

    CrmService service = CRMService.GetServiceReference();
    quote oldQuote = (quote)service.Retrieve(EntityName.quote.ToString(), new Guid(Request.QueryString["id"]), new AllColumns());
    quote newQuote = oldQuote;
    service.Create(newQuote); // exception thrown here

    What do I need to do with newQuote to enable it to save?

    Thanks

     


    You need to nullify the quote identifier (to avoid duplicate key errors):

    quote newQuote = oldQuote;
    newQuote.quoteid = null;
    
    service.Create(newQuote); // exception thrown here
    

    --pogo (pat)
    Friday, January 14, 2011 1:04 AM

All replies

  • Hi,

    I'm trying to develop a module to clone quotations, so far I have this but it always throws an exception "Server was unable to process request"

    CrmService service = CRMService.GetServiceReference();
    quote oldQuote = (quote)service.Retrieve(EntityName.quote.ToString(), new Guid(Request.QueryString["id"]), new AllColumns());
    quote newQuote = oldQuote;
    service.Create(newQuote); // exception thrown here

    What do I need to do with newQuote to enable it to save?

    Thanks

     


    You need to nullify the quote identifier (to avoid duplicate key errors):

    quote newQuote = oldQuote;
    newQuote.quoteid = null;
    
    service.Create(newQuote); // exception thrown here
    

    --pogo (pat)
    Friday, January 14, 2011 1:04 AM
  • Thanks a lot, that works great.

    Taking this one step further, how would I retrieve all the quotedetail items associated with oldQuote and then assign copies of them to newQuote?

    Thanks

    Friday, January 14, 2011 1:45 AM
  • Something like this:

    Guid oldQuoteId = new Guid("2EBE2BC0-AB51-DE11-ABD4-001517418135");
    
    quote quote = (quote)crmService.Retrieve(EntityName.quote.ToString(), oldQuoteId, new AllColumns());
    quote.quoteid = null;
    
    Guid newQuoteId = crmService.Create(quote);
    
    QueryByAttribute query = new QueryByAttribute();
    query.EntityName = EntityName.quotedetail.ToString();
    query.Attributes = new string[] { "quoteid" };
    query.Values = new object[] { oldQuoteId };
    query.ColumnSet = new AllColumns();
    
    BusinessEntityCollection lineItems = crmService.RetrieveMultiple(query);
    
    foreach (quotedetail lineItem in lineItems.BusinessEntities)
    {
    	lineItem.quotedetailid = null;
    	lineItem.quoteid = new Lookup(EntityName.quote.ToString(), newQuoteId);
    
    	crmService.Create(lineItem);
    }
    
    

    --pogo (pat)
    Friday, January 14, 2011 1:56 AM
  • Thanks a lot - this looks great apart from this line won't compile

    lineItem.quoteid = new Lookup(EntityName.quote.ToString(), newQuoteId);

    "CRMService.Lookup does not contain a constuctor that takes 2 arguments"

    Thanks

     

    Friday, January 14, 2011 2:21 PM
  • I can't remember if it is the CRM SDK or the web service that creates an object model as such, but for whichever it is, you need to use:

    lineItem.quoteid = new Lookup();
    lineItem.quoteid.type = EntityName.quote.ToString();
    lineItem.quoteid.Value = newQuoteId;
    
    

    --pogo (pat)
    Sunday, January 16, 2011 11:12 PM