'MS CRM 2011 copy quote

I am working with MS CRM 2011 since 4 weeks. I must copy an existent quote to a new one.

Which way is the best way to do this? With Javascript or a C# aspx Homepage?

Can some give me an example how to do this?



Solution 1:[1]

There's a number of ways to do it. Here are two.

URL Initialization

http://www.renauddumont.be/en/2011/crm-2011-passing-field-values-to-a-form-using-url-parameters

http://msdn.microsoft.com/en-us/library/gg334436.aspx

http://msdn.microsoft.com/en-us/library/gg334375.aspx

I've implemented this before, for contacts. My requirements fit the URL initialization method best. I can see an advantage of this technique for quotes as well. For this method, I too would recommend Gareth Tucker's blog entry describing how to do it.

I used several elements of Gareth's post, but I factored my end script into something a little more compact. In essence, you use javascript to pull values for specific fields and arrange them as query string parameters into a specially formed CRM Form URL. This url unpacks the query string parameters and assigns the corresponding fields in a new form the values that you passed. This works great when you have an item open and you want to clone it and leave the new form open for the user to edit.

I ended up calling this script, which was added as a web resource, from the Contact form Ribbon. Gareth does a good job of explaining how to do this as well.

// Register this namespace to avoid collision with other scripts that may 
// run within this form 
Type.registerNamespace("BF.Contact");

    // Create a function that will be called by a ribbon button.
BF.Contact.Clone = function() {


    var extRaqs = "";

    // ownerid
    extRaqs += "&ownerid=" + Xrm.Page.getAttribute("ownerid").getValue()[0].id;
    extRaqs += "&owneridname=" + Xrm.Page.getAttribute("ownerid").getValue()[0].name;
    extRaqs += "&owneridtype=systemuser"; 

    extRaqs += BF.Contact.Clone.GetValue("address1_line1"); 
    extRaqs += BF.Contact.Clone.GetValue("address1_line2"); 
    extRaqs += BF.Contact.Clone.GetValue("address1_city");  
    extRaqs += BF.Contact.Clone.GetValue("address1_postalcode");    
    extRaqs += BF.Contact.Clone.GetValue("mobilephone");
    extRaqs += BF.Contact.Clone.GetValue("telephone1"); 
    extRaqs += BF.Contact.Clone.GetValue("telephone2");
    extRaqs += BF.Contact.Clone.GetValue("fax");    
    extRaqs += BF.Contact.Clone.GetValue("emailaddress1");
    extRaqs += BF.Contact.Clone.GetValue("address1_county");    

    extRaqs += "&donotsendmm=1"


    var newURL = Xrm.Page.context.getServerUrl() + "/main.aspx?etn=contact&pagetype=entityrecord&extraqs=";

    newURL += encodeURIComponent(extRaqs);

    window.open(newURL , "_blank", "width=900px,height=600px,resizable=1");
}

BF.Contact.Clone.GetValue = function(attributename) {
    var _att = Xrm.Page.getAttribute(attributename);
    var _val = "";


    if (_att == null || _att.getValue() == null ) {
        return "";
    }

    if (_att.getFormat() == "date") {
        _val = _att.getValue().format("MM/dd/yyyy");
    } else {
        _val = _att.getValue();
    }

    return "&" + attributename + "=" +  _val;
}

Some drawbacks:

  1. Only really works if you have the form open of the item you want to clone.
  2. Only works one item at a time.
  3. URLs have limits, and for really big entities / fields not all things can be cloned.

Workflow / Dialog

If you want to be able to clone a number of items a really quick way to do this is to create a workflow or dialog targeting the entity you want to clone. In the workflow, create a new item of the type that is targeted. The newly created item's properties can be set to whatever your requirements are. Default them to static values, populate them with values from the cloned item, or anything else permissible by workflow. One primary drawback is that presenting the form to the user is not going to be available.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jason Koopmans