Thursday, May 22, 2008

Cloning An Entity In CRM

Danny Varghese on 03.26.08 wrote

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!

 



No comments: