<title>CRM Bookmarklets</title>
<h1>CRM Bookmarklets</h1>

<p>Click and drag the link to your favourites or bookmark bar.</p>

<div>
	<p><a href="javascript:(function(n){try{var t=n.Xrm.Page.data.entity.getId();if(!t)return alert('Failed to find id on this form.');window.clipboardData?window.clipboardData.setData('Text',t):window.prompt('Copy to clipboard: Ctrl+C, Enter',t)}catch(i){alert('Error occurred while retrieving record id. '+i.message)}})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Copy Record Id</a>
<br/><strong>Copies the record id to the clipboard.</strong>  If copy to clipboard is not supported then provides you with a prompt window to copy the link.</p><p><a href="javascript:(function(n){try{var i=n.Xrm.Page.data.entity.getId(),r=n.Xrm.Page.data.entity.getEntityName(),t=n.Xrm.Page.context.getClientUrl();if(!i)return alert('Failed to find id on this form.');t=[t,'/main.aspx?','etn=',r,'&id=',i,'&pagetype=entityrecord'].join('');window.clipboardData?window.clipboardData.setData('Text',t):window.prompt('Copy to clipboard: Ctrl+C, Enter',t)}catch(u){alert('Error occurred while retrieving record url. '+u.message)}})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Copy Record Link</a>
<br/>Copies the link to the record to the clipboard.  If copy to clipboard is not supported then provides you with a prompt window to copy the link.</p><p><a href="javascript:(function(n){n.Xrm.Page.ui.controls.forEach(function(n){n&&n.setDisabled&&n.setDisabled(!1)});n.Xrm.Page.data.entity.attributes.forEach(function(n){n&&n.setSubmitMode&&n.setSubmitMode('always')})})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Enable All Fields</a>
<br/>Enable all fields on the form</p><p><a href="javascript:(function(n){try{n.APPLICATION_VERSION=='6.0'?typeof n._IsRefreshForm!='undefined'&&n._IsRefreshForm=='1'?n.OpenPerformanceUI(!0):n.OpenPerformanceUI():n.APPLICATION_VERSION==='6.1'||/^7\.\d+$/.test(n.APPLICATION_VERSION)?n.Mscrm.Performance.PerformanceCenter.get_instance().TogglePerformanceResultsVisibility():alert('This feature is not supported on this version of Dynamics CRM.')}catch(t){alert('Error occurred opening performance report. '+t.message)}})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Open Performance Report</a>
<br/>Opens the PerformanceUI window, if supported by your version of CRM.</p><p><a href="javascript:(function(n){try{n.Xrm.Page.data.refresh(!1)}catch(t){alert('Error occurred while retrieving record id. '+t.message)}})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Refresh From data</a>
<br/>Asynchronously refresh the form.</p><p><a href="javascript:(function(n){try{n.Xrm.Page.data.refresh(!0)}catch(t){alert('Error occurred while retrieving record id. '+t.message)}})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Save and Refresh From data</a>
<br/>Asynchronously save and refresh the form.</p><p><a href="javascript:(function(n){n.Xrm.Page.ui.controls.forEach(function(n){n.setVisible(!0)});n.Xrm.Page.ui.tabs.forEach(function(n){n.setVisible(!0);n.sections.forEach(function(n){n.setVisible(!0)})})})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Show All fields</a>
<br/>Sets the visibility to true for all fields on the form.</p><p><a href="javascript:(function(n){var t=[];n.Xrm.Page.data.entity.attributes.forEach(function(n){n&&n.getIsDirty&&n.getIsDirty()&&t.push(n.getName())});t&&t.length?alert(['The following attributes are currently dirty: \n',t.join(', ')].join('')):alert('No attributes appear to be dirty on the current form.')})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Show Dirty Fields</a>
<br/>Alerts a message listing all the dirty attributes (fields that have changed) on the form.</p><p><a href="javascript:(function(n){n.Xrm.Page.ui.controls.forEach(function(t){if(t.getControlType()=='optionset'){var i='<br /><b><u>Name: '+t.getName()+'<\/u><\/b><br />';n.$('#'+t.getName()+'_i').find('option').first().nextAll().each(function(){i+='<div><i>Value:<\/i> '+$(this).attr('value')+' - <i>Text:<\/i> '+$(this).attr('title')+'<\/div>'});osa+='<div>'+i+'<\/div>'}});window.open('#','#').document.open().write('<div style=\'font-family:Segoe UI,Arial;font-size:11px;overflow:always\'>'+osa+'<\/div>')})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Show OptionSet Values</a>
<br/>Opens up a window and displays the option set and their possible values</p><p><a href="javascript:(function(n){n.Xrm.Page.ui.controls.forEach(function(n){n.setLabel(n.getName())})})(function(){if(!window.APPLICATION_VERSION)return alert('Could not determine the current version of CRM.');if(window.APPLICATION_VERSION==='5.0')return window.top.frames[0];if(/^[6,7]\.\d+$/.test(window.APPLICATION_VERSION)){var n=$('#crmContentPanel iframe:not([style*=\'visibility: hidden\'])');return n.length>0&&n[0].contentWindow.Xrm.Page.ui?n[0].contentWindow:alert('[CRM 2013/2015] Could not locate the entity form.')}return window.APPLICATION_VERSION?alert('Unsupported CRM Version Detected: '+window.APPLICATION_VERSION):alert('Unable to detect current CRM Version.')}(window))">Show Schema Names</a>
<br/>Changes all the labels on the form to display their schema names instead of their display names.</p>
</div>

<h1>Add/Rebuild Bookmarklets</h1>
Create a new Javascript file.  The object 'formContext' is the context object of the form, and you can access the Xrm.Page api from it.

Run the BookmarkBuilder.exe to rebuild the Bookmarklets.html page with the minified bookmarklets.