Search code examples
dynamics-crmdynamics-crm-onlinedynamics-crm-2015xrmdynamics-crm-2016

Try to add an click event on CRM online Control in Javascript with XRM


I try to add an event on a field in my CRM online control

There is my code to addIt ... but nothing work. It's there a way to do it ?

This code is execute on my formLoad

var issueKey = Xrm.Page.getAttribute("myControl").getValue();
    if (issueKey != "") {
        Xrm.Page.getControl("myControl").onClick = function () {
            window.open(BaseUrl, "_blank");
        };
    }

Solution

  • What you're asking to do is unsupported (https://msdn.microsoft.com/en-us/library/gg334481.aspx). And calling Xrm.Page.getControl("myControl") returns back an XRM control, not a DOM object. You have two options:

    1. Go extremely unsupported, add JQuery to the page, and spend some time finding the correct DOM object and adding an onclick event to it.
    2. Create Web Resource that looks like the control you need (you could even add some JS events to wire it back to a hidden field on the form), and add an On Click event to that via standard JS/HTML.