Search code examples
hyperlinkdynamics-crm-2013webresource

Linking to record from external webresource in CRM 2013


I have a calendar that displays activities from CRM 2013. This calendar is hosted as a separate MVC4 application.

I can surf to and use the calendar either by going directly to it at calendar.domain.com or by clicking my way to it inside of CRM.

In the details of each event there is a link to the original CRM activity, and by clicking on it a new window opens pointing to the original CRM entity.

This latter part with the link works great outside of crm when you are using the calendar directly, but when the page is integrated inside of CRM 2013 the new window points back to the calendar. Its like CRM is blocking the opening of the page and pointing it back to the originating source.

I have integrated the calendar inside of CRM using a webresource with the following html and the sitemap editor:

<html>
<head>
    <meta charset="utf-8">
</head>
<body>
    <script type="text/javascript">
        window.location.href = "https://calendar.domain.com/";
    </script>
</body>
</html>

When you go to in CRM, it redirects to the calendar seamlessly.

I have tried creating links with target="_parent" and target="_blank" but both result in the same thing, works outside of CRM, but inside crm the new page just shows the calendar again.

I also tried to use javascript to redirect the page, but the result is still the same.

<a href="#" onclick="javascript:openUrl('<<url>>');return false;">CRM Activity link</a>

function openUrl(rurl) {
    window.open(rurl);
}

I know there are ways to open entities using SDK functions but I am hoping I can avoid that so that I can use the same calendar both inside and out of CRM.


Solution

  • Using trial and error I arrived at a javascript function that opens the record as a new page, it works both outside and as an page embedded inside crm 2013.

    I'm calling the function with something like this:

    openEntityRecord("activity", "1234-45687-6785-2342", "https://contoso.mydomain.com");
    

    Function:

    function openEntityRecord(enityLogicalName, guid, baseUrl) {
        var randomnumber = 100000000 + Math.floor(Math.random() * 900000000);
        var url = baseUrl + "main.aspx?etn=" + enityLogicalName + "&extraqs=&histKey=" + randomnumber + "&id={" + guid + "}&newWindow=true&pagetype=entityrecord";
        window.open(url, "", "status=0,resizable=1,width=1000px,height=600px");
    }