Search code examples
browserdynamics-crmdynamics-crm-2013

Showing shareable URLs in the address bar of Dynamics CRM?


I would like to enable shareable URLs (shown as https://crm.myorg.com/main.aspx?etc=X&extraqs=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&pagetype=XXXXXXX) to be displayed directly in the address bar, instead of having to click "Email a link" and retrieving the URL from there. Right now each page shows the URLs as https://crm.myorg.com/main.aspx#XXXXXXXX

Is there a way to do it? I am using MS CRM Dynamics 2013 On-Premise.

Thank you.


Solution

  • I've managed to solve this with a JS hack.

    1. Add the code below to a JS Web Resource
    2. Set the OnLoad method of a chosen entity to call the SetAddressBarAsFormShortcut() function

    Note that unfortunately it's impossible to enable this behavior globally (unless Microsoft's JS files are modified) and it only works for browsers supporting the history.pushState() method.

    function UpdateAddressBar(entityTitle, recordId, entityLogicalName) {
        var $v_0 = Mscrm.CrmUri.create(window.location.href);
        if (Mscrm.SessionInfo.isOutlookLaptopClient() && !Mscrm.SessionInfo.isOnline()) {
            var $v_2 = window.location.href, $v_3 = window.location.pathname;
            $v_0 = Mscrm.CrmUri.create(Mscrm.Help.concatenateUrl(window.WEB_APP_URL, $v_2.substr($v_2.indexOf($v_3))));
            $v_0.set_useOrganizationName(false)
        }
        if (!Mscrm.Utilities.isNewPageModel($v_0)) {
            $v_0 = Mscrm.Utilities.removeExtraQSParameters($v_0, Mscrm.Utilities.getRecordPageQueryStringParams());
            if (Mscrm.InternalUtilities.EntityNames.Calendar === entityLogicalName && (IsNull($v_0.get_query()["id"]) || isNullOrEmptyString($v_0.get_query()["id"])) && !IsNull(recordId)) {
                $v_0.get_query()["calendarId"] = recordId;
                $v_0.get_query()["calendarType"] = 1;
                $v_0 = Mscrm.Utilities.removeExtraQSParameters($v_0, ["calendarId", "calendarType"])
            }
        } else {
            $v_0 = Mscrm.Utilities.getPageUrl($v_0, "entityrecord");
            delete $v_0.get_query().pagemode;
            if (!IsNull(recordId))
                $v_0.get_query()["id"] = recordId;
            delete $v_0.get_query().extraqs;
            var $v_4 = $find("crmFormSelector");
            if ($v_4)
                $v_0.get_query()["extraqs"] = "formid=" + CrmEncodeDecode.CrmUrlEncode($v_4.$r_3)
        }
        $v_0 = $v_0.toString();
        $v_0 = $v_0.substring($v_0.indexOf("main.aspx"));
        top.onpopstate = function(){top.history.pushState("", "", "main.aspx"); top.onpopstate = null; top.history.go(-2)};
        top.history.pushState("", "", $v_0);     
    };
    
    function SetAddressBarAsFormShortcut() {
        var $v_0 = Xrm.Page.data.entity;
        UpdateAddressBar(CrmEncodeDecode.CrmHtmlDecode($v_0.getPrimaryAttributeValue()), $v_0.getId(), $v_0.getEntityName())
    }
    

    (The code above is based on the code Microsoft uses in the Email a link/Copy a link function)