CRM Blog

Cloning An Entity In CRM

by Danny Varghese 03.26.08

Intro

We’ve had requests from our clients to “clone” already created records at the click of a button.  The reason is that when users are entering data into numerous records of the same entity every day, where only a few fields may differ, it can be cumbersome.  A great example is we created an entity with over 50 fields and users may create 10-15 records of that entity where 90% field values will be the same.   I’ll explain the approach we took.

Approach

1.       Create a JavaScript function that will open a window to the entity to be cloned to (make the window variable global)

2.       Edit the ISV.config.xml to add a button, and in the configuration, reference the JavaScript function created above

3.     Inside the JavaScript function (you may create other methods as well), call the function to check the status of the new window

4.    When the page is loaded, start mapping from one window to the other as in the second function below

function checkPageState()

{              if (oClonedEntity.document.readyState == 'complete')               {                   cloneEntity();                          return;         }  

  setTimeout('checkPageState()',100);            

}     
function cloneEntity(){            
with(oClonedEntity.document.crmForm)       {             

    //add fields here that you want to copy from one entity to the newly created one

    new_field1.DataValue = crmForm.all.new_field1.DataValue;                  new_field2.DataValue = crmForm.all.new_field2.DataValue;       }                            //finally, close the dialog       

window.close();

} 
5.       After inserting the above code, test it out.  This will be highly beneficial for users, enjoy!

 

Comments

# Eran said on June 14, 2008 07:06 PM:

Nice technique, simple and elegant, worx great!

# Ian Randall said on June 17, 2008 07:32 PM:

Nice...

The only drawback of this approach is that you cannot clone an entity's fields that are not on the form. We recently had a fairly large custom entity that would show/hide stuff based on picklist values selected at runtime, and we needed to clone the whole thing... so we abstracted this functionality into a .net WF library and invoked it from a CRM Workflow.

Using javascript would have been much neater though!

-- Ian Randall, Auckland --

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Security Check
Please answer the simple math problem below.

(required)