Lookups (including partylist and customer) cannot be copy pasted. I have encountered couple of scenarios where I needed this capability. I have developed these bookmarklets to solve this issue.
Copy Lookup
Select and the drag the code below to the bookmark bar.
javascript:(function(){let contentPanels=Array.from(document.querySelectorAll('iframe')).filter(function(d){return d.style.visibility!=='hidden'});if(contentPanels&&contentPanels.length>0){let Xrm=contentPanels[0].contentWindow.Xrm;let currentControl=Xrm.Page.ui.getCurrentControl();if(currentControl&¤tControl.getControlType()==='lookup'){let currentLookup=currentControl.getAttribute().getValue();if(currentLookup){let serialisedLookupValue=JSON.stringify(currentLookup.map(x=>{let c={};({id:c.id,name:c.name,type:c.type,typename:c.typename,entityType:c.entityType}=x);return c;}));sessionStorage.setItem('ryr_serialisedLookup',serialisedLookupValue);alert('Lookup copied. Ready to paste');}}else{alert('No field has been selected or the currently selected field is not a lookup');}}else{alert('Entity form not detected');}})();void 0;
Source:
(function () { let contentPanels = Array.from(document.querySelectorAll('iframe')).filter(function (d) { return d.style.visibility !== 'hidden' }); if (contentPanels && contentPanels.length > 0) { let Xrm = contentPanels[0].contentWindow.Xrm; let currentControl = Xrm.Page.ui.getCurrentControl(); if (currentControl && currentControl.getControlType() === 'lookup') { let currentLookup = currentControl.getAttribute().getValue(); if (currentLookup) { let serialisedLookupValue = JSON.stringify( currentLookup.map(x = > { let c = {}; ({ id : c.id, name : c.name, type : c.type, typename : c.typename, entityType : c.entityType } = x); return c; })); sessionStorage.setItem('ryr_serialisedLookup', serialisedLookupValue); alert('Lookup copied. Ready to paste'); } } else { alert('No field has been selected or the currently selected field is not a lookup'); } } else { alert('Entity form not detected'); } })();
Paste Lookup
Select and the drag the code below to the bookmark bar.
javascript:(function(){let contentPanels=Array.from(document.querySelectorAll('iframe')).filter(function(d){return d.style.visibility!=='hidden'});if(contentPanels&&contentPanels.length>0){let Xrm=contentPanels[0].contentWindow.Xrm;let currentControl=Xrm.Page.ui.getCurrentControl();if(currentControl&¤tControl.getControlType()==='lookup'){let currentLookup=currentControl.getAttribute();let copiedLookupValue=sessionStorage.getItem('ryr_serialisedLookup');if(copiedLookupValue){currentLookup.setValue(JSON.parse(copiedLookupValue));} else{alert('Please select a lookup to copy first before pasting');}}else{alert('No field has been selected or the currently selected field is not a lookup');}}else{alert('Entity form not detected');}})();void 0;
Source:
(function () { let contentPanels = Array.from(document.querySelectorAll('iframe')).filter(function (d) { return d.style.visibility !== 'hidden' }); if (contentPanels && contentPanels.length > 0) { let Xrm = contentPanels[0].contentWindow.Xrm; let currentControl = Xrm.Page.ui.getCurrentControl(); if (currentControl && currentControl.getControlType() === 'lookup') { let currentLookup = currentControl.getAttribute(); let copiedLookupValue = sessionStorage.getItem('ryr_serialisedLookup'); if(copiedLookupValue){ currentLookup.setValue(JSON.parse(copiedLookupValue)); } else{ alert('Please select a lookup to copy first before pasting'); } } else { alert('No field has been selected or the currently selected field is not a lookup'); } } else { alert('Entity form not detected'); } })();
Instructions
- Select the lookup field to be copied. The lookup will usually be highlighted with a blue background when it is selected
- Run the Copy Lookup bookmarklet. You will get a alert message confirming that the lookup has been copied
- Select the lookup field that is the target of the paste. The lookup has to be of the same type i.e. if the copied lookup was a contact lookup, the target lookup also has to be a contact lookup
- Run the Paste Lookup bookmarklet
- Save the record
I have tested these bookmarklets only in Chrome 53 and Firefox 50.
