web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Copy Link button javascript

(0) ShareShare
ReportReport
Posted on by 1,328

I'm trying to use this code to add a 'Copy Link' button using Ribbon Workbench. I got this from a bookmarklet that was provided in another thread. After publishing, nothing happens when I click the button. Can someone help me with my code?

function copyLink(){
    var contentPanels=Array.from(document.querySelectorAll('iframe')).filter(function(d){return d.style.visibility!=='hidden'});
    if (contentPanels && contentPanels.length > 0) {
        var Xrm = contentPanels[0].contentWindow.Xrm; var entityId = Xrm.Page.data.entity.getId();
        if(entityId){
            prompt('Ctrl+C to copy to clipboard',Xrm.Page.context.getClientUrl()+'/main.aspx?etn='+Xrm.Page.data.entity.getEntityName()+'&id='+entityId+'&newWindow=true&pagetype=entityrecord');
        }
    }
}


Code from bookmarklet:

javascript:(function(){var%20contentPanels=Array.from(document.querySelectorAll('iframe')).filter(function(d){return%20d.style.visibility!=='hidden'});if(contentPanels&&contentPanels.length>0){var%20Xrm=contentPanels[0].contentWindow.Xrm;var%20entityId=Xrm.Page.data.entity.getId();if(entityId){prompt('Ctrl+C%20to%20copy%20to%20clipboard',Xrm.Page.context.getClientUrl()+'/main.aspx?etn='+Xrm.Page.data.entity.getEntityName()+'&id='+entityId+'&newWindow=true&pagetype=entityrecord');}}})();void%200;

4024.Capture.PNG

*This post is locked for comments

I have the same question (0)
  • Verified answer
    epark06 Profile Picture
    1,328 on at
    RE: Copy Link button javascript

    Resolved using:

    function copyLink(){

       var entityId = Xrm.Page.data.entity.getId();

           if(entityId){

               prompt('Ctrl+C to copy to clipboard',Xrm.Page.context.getClientUrl()+'/main.aspx?etn='+Xrm.Page.data.entity.getEntityName()+'&id='+entityId+'&newWindow=true&pagetype=entityrecord');

           }

       }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans