Copy CRM Contents To The Clipboard
I had a client ask whether or not I could add a button to the Account Form in CRM that would copy and format the address so that they could paste it into an Email or a Word document. There is a function that you can call from Javascript/VBScript that will allow you to copy text, URLs etc to the clipboard for use in other applications: window.clipboardData.setData(tag,value);
Step 1: Determine which fields on the Form we need to capture and the schema name
- In this case we wanted to capture the following:
- Account Name (name)
- Street 1 (address1_line1)
- Street 2 (address1_line2)
- City (address1_city)
- State (address1_stateorprovince)
- Zip Code (address1_postalcode)
Step 2: Write the necessary Javascript in Notepad (case sensitive)
var texttocopy;
try
{
texttocopy = crmForm.all.name.DataValue + '\n';
texttocopy += crmForm.all.address1_line1.DataValue + '\n';
texttocopy += crmForm.all.address1_line2.DataValue + '\n';
texttocopy += crmForm.all.address1_city.DataValue + ', ' + crmForm.all.address1_stateorprovince.DataValue + ' ' + crmForm.all.address1_postalcode.DataValue + '\n';
window.clipboardData.setData('Text',texttocopy);
}
catch(e)
{}
Step 3: Edit the isv.config.xml file to add the Copy Address button
- Browse to the isv.config.xml file (<crm_website_folder\_Resources\isv.config.xml)
- Make a backup copy of isv.config.xml file
- Open isv.config.xml with Notepad
- Add the following line between the <Entities></Entities> XML Tags
- <Entity name="account">
- <ToolBar ValidForCreate="1" ValidForUpdate="1">
- <Button Title="Copy Address" ToolTip="Copies the Account Address To The Clipboard" Icon="/_imgs/ico_18_4004.gif" JavaScript=" " />
- </ToolBar>
- </Entity>
- Copy and Paste your Javascript from Step 2 between the double quotes in Line 3
- Save the isv.config.xml file
Step 4: Test the Button
- Open up an Account In CRM
- Click the Copy Address button
- Open Wordpad/Work/Outlook or some other application
- Click Edit -> Paste or hit Ctrl + V
- The formatted address from CRM should appear
This will work on IE 6.0 and IE 7.0. The window.clipboardData.setData function can also be used to copy URLs. If you want to copy the URL of the open record use this Javascript instead:
var url;
url = window.location.href;
window.clipboardData.setData('Text',url);