web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Create A Copy Of A Quote

(0) ShareShare
ReportReport
Posted on by

Hi,

I'm wondering if it is possible to create a copy of a quote. Basically I would need to get all the data from the quote and pass them over to a new form which would obviously have a different quote ID.

I know how to pass data to another form via parameters, however within a Quote there are products which is done via a sub-grid. These products would also need to be passed over.

Can this be done?

Thanks, Shaun

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Create A Copy Of A Quote

    This may help you

    stackoverflow.com/.../ms-crm-2011-copy-quote

  • Community Member Profile Picture
    on at
    RE: Create A Copy Of A Quote

    Hi Bryn,

    Unfortunately that link only shows me what I already know, my issue is how to get the data from a sub grid and copy that over to a new form

    Thanks, Shaun

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: Create A Copy Of A Quote

    Hi Shaun,

    You can create copy of quote.. using custom workflow activity or JavaScript..

    If you are doing by any method, first you need to create Quote Record, then only you can add product to that quote.

    Suppose you have Quote A with Product 1 & product 2, and want to create copy of Quote A, then First you need to create copy of Quote A as B either using workflow activity or JavaScript, Save Quote B and then add product details from Quote A to Quote B using workflow activity or JavaScript.

    Quote products are stored in  quotedetail entity and this entity sub grid is shown on Quote Form.

    In CRM application, you can create child element only when parent is saved..and for quote Quote is parent and Quotedetail (Quote Product) is child.

    Hope this will help..

  • Community Member Profile Picture
    on at
    RE: Create A Copy Of A Quote

    Hi Magadeo,

    Thank you for your post, I will be using JS as I found this post which is quite useful

    community.dynamics.com/.../clone-records-in-dynamics-crm.aspx

    However I have encountered some difficulties with it, from what your saying I can retrieve the product that is in the sub grid by using quotedetail, this makes sense to me however how do I do it so that only the product that is in the sub grid is copied?

    Thanks, Shaun

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: Create A Copy Of A Quote

    You need to retrieve products from Quote A, and need to create in Quote B.

    To retrieve products for Quote A from quoteDetail you have to use Quote A GUID / RecordId.

    So your steps will be like..

    1. Retrieve Quote A data (not products)

    2. Create Quote B

    3. Retrieve Quote A products from QuoteDetails

    4. Insert Quote A products into Quote B products.  

    In Case if you just need to copy products from Quote A to Quote B,

    then only retrieve Quote A products and insert into Quote B products.

    All above operations you need to do through code only.. either JS or workflow..

    Hope this will help you to understand more in details.

  • Community Member Profile Picture
    on at
    RE: Create A Copy Of A Quote

    Hi Mahadeo

    Thanks again for your reply, I understand the logic its just the actual code im struggling with as I can't find any good examples.

    What I have so far is;

    Quote A when the function to create a quote is triggered JS will get the id of the Quote A and pass that as a parameter to the new Quote B (other data will be passed over once it is working)

    Quote B then can use the guid of quote A to select the products that is associated with Quote A.

    However I'm unsure if the code I am using is actually correct for retrieving the products from Quote A and I have no idea how to then use the retrieved products to populate Quote B's sub grid.

    So far I have

      var option = "$select=QuoteDetailId&$filter=QuoteId/Id eq guid'" + id + "'";
      SDK.REST.retrieveMultipleRecords("QuoteDetail", option, retrieveData, function(error) { alert(error.message); }, function(){});
    

    As Stated I am unsure if this is even bringing me the data I want and if it is I don't know what then to do with it

    Thanks, Shaun
     

  • Community Member Profile Picture
    on at
    RE: Create A Copy Of A Quote

    For anyone who is following this, I have an Update on the progress made;

    Firstly using the following code, I can retrieve the product id's that has been selected within Quote A
    (for now I am not passing anything over to quote B during the testing phase but it will be done once I have the logic worked out. For now the function is being called for onSave)

    function cloneQuote()
    {
      var id =Xrm.Page.data.entity.getId();
      var option = "$select=QuoteDetailId&$filter=QuoteId/Id eq guid'" + id + "'";
      SDK.REST.retrieveMultipleRecords("QuoteDetail", option, retrieveData, function(error) { alert(error.message); }, function(){});
    
    }
    
    function retrieveData(retrievedData)
    {
      if(retrievedData.length > 0)
      {
         for(I=0; I<retrievedData.length; I++)
         {
           alert(retrievedData[I].QuoteDetailId);
         }
      }
    }


    This will now pop up an alert box of ID's for each product that is in the sub grid

    My issue now is when I am in Quote B how do I use these ID's to input the data into quote b's subgrid.

    If anyone knows please share as this is most important to me

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: Create A Copy Of A Quote

    your code should similar to this..

    1. Retireve Quote A Products

    SDK.REST.retrieveMultipleRecords(
         "QuoteDetail",
         option,
         function (results) {
    	 	  
    	   for (var i = 0; i < results.length; i++) {
    //Copy / Create Quote A products into Quote B var product={}; //Set ohter required attrbitues of products product.productid= results[i].productid; product.quantity=results[i].quantity; product.quoteid = "QuoteId of Quote B"; //create quote product SDK.REST.createRecord(product,"quotedetail",function(){},function(error) { alert(error.message); },function(){}); } }, function(error) { alert(error.message); }, function () { //OnComplete handler } );


  • Community Member Profile Picture
    on at
    RE: Create A Copy Of A Quote

    Hi Again Mahadeo,

    Sorry for the delay, I only work twice a week in-between university

    I have implemented what you suggested, however I  keep getting the following error;

    Error: 400 : Bad Request: Error processing request steam. The request should be a valid top-level resource object

    For now I am only trying to add the product id to the quotedetail via the following

    function getQuoteCopyProducts()
    {
    
      var copyCheck = Xrm.Page.getAttribute("new_quotecopyid").getValue();
      if (copyCheck!=null)
      {
             
        var option = "$select=QuoteDetailId&$filter=QuoteId/Id eq guid'" + copyCheck + "'";
    
        SDK.REST.retrieveMultipleRecords("QuoteDetail", option, retrieveData, function(error) { alert(error.message); }, function(){});
      }
    }
    
    function retrieveData(result)
    {
      if(result.length >0)
      {
    
      var id =Xrm.Page.data.entity.getId();
    
        for (var I=0; I<result.length; I++)
        {
          var product={};
    
          product.QuoteDetailId=result[I].QuoteDetailId;
    
          product.QuoteId = id;
    
    
          SDK.REST.createRecord(product, "QuoteDetail",function(){},function(error) { alert(error.message); },function(){});
          alert("Product Has Been Created");
        }
       }
       else
      {
        alert("error");
      }
    }


  • Community Member Profile Picture
    on at
    RE: Create A Copy Of A Quote

    To anyone who is following this question

    I have made a few changes and I am now getting the following error;

    Error: 400 : Bad Request: Error processing request stream. The Property name 'productid' specified for type 'Microsoft.Crm.Sdk.Data.Services.QuoteDetail' is not valid

    The Code is now as follows ;

    function retrieveData(result)
    {
      if(result.length >0)
      {

      var id =Xrm.Page.data.entity.getId();

        for (var I=0; I<result.length; I++)
        {

          var product={};

          product["productid"]= result[I].ProductId;

          product["quoteid"] = id;


          SDK.REST.createRecord(product, "QuoteDetail",function(){},function(error) { alert(error.message); },function(){});
         }
       }
       else
      {
        alert("error");
      }
    }

    function retrieveData(result)
    {
      if(result.length >0)
      {
    
      var id =Xrm.Page.data.entity.getId();
    
        for (var I=0; I<result.length; I++)
        {
    
          var product={};
    
          product["productid"]= result[I].ProductId;
    
          product["quoteid"] = id;
    
    
          SDK.REST.createRecord(product, "QuoteDetail",function(){},function(error) { alert(error.message); },function(){});
         }
       }
       else
      {
        alert("error");
      }
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans