简体   繁体   中英

preventing opening of record on double click in dynamics 365

I have set up a Queue for our Abstract entity. I am trying to prevent the double click opening of the record. I have set up a handler for the event, and call.stopPropagation() and.preventDefault() on the event object, and it continues to open up the window.

Not sure if I'm missing something obvious or what.. here's my code:

function attachDoubleClick() {
    var grid = document.getElementById("gridBodyTable");
    if (grid == null) {
        setTimeout(function () { attachDoubleClick(); }, 2000); //if the grid hasn’t loaded run this again
        return;
    }

    function handler(e) {
        var abstractId = document.getElementsByClassName("ms-crm-List-SelectedRow").item().getAttribute("oid").replace("}", "").replace("{","");
        XrmSvcToolkit.retrieve({
            entityName: "prod_abstract",
            id: abstractId,
            select: ["prod_abstractstatus"],
            async: false,
            successCallback: function (result) {
                if (result.prod_abstractstatus.Value != 108410000) {
                    alert("This abstract is already being worked on or is completed.");
                    e.stopPropagation();
                    e.preventDefault();
                    console.log(e);
                    return;
                }
            },
            errorCallback: function (error) {
                console.log(error);
            }
        });
    }
    grid.ondblclick = handler;
}


The issue was I needed to addEventListener with a 3rd parameter of true. (this is the useCapture parameter.) End code looked like this:

function attachDoubleClick() {
    var grid = document.getElementById("gridBodyTable");
    if (grid == null) {
        setTimeout(function () { attachDoubleClick(); }, 2000); //if the grid hasn’t loaded run this again
        return;
    }
    grid.addEventListener("dblclick", handler, true);
}


function handler(e) {
    console.log(e);
    var abstractId = document.getElementsByClassName("ms-crm-List-SelectedRow").item().getAttribute("oid").replace("}", "").replace("{", "");
    XrmSvcToolkit.retrieve({
        entityName: "prod_abstract",
        id: abstractId,
        select: ["prod_abstractstatus"],
        async: false,
        successCallback: function (result) {
            if (result.prod_abstractstatus.Value != 108410000) {
                alert("This abstract is already being worked on or is completed.");
                e.stopPropagation();
                e.preventDefault();
                return;
            }
        },
        errorCallback: function (error) {
            console.log(error);
        }
    });

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM