Subgrid: Restrict user to select only one record

ぐ巨炮叔叔 提交于 2019-12-11 23:14:00

问题


i have a subgrid on a custom entity form where i am showing related records for Case Entity. I want to restrict user to select only one record. How can i achieve this using javascript in crm 2011


回答1:


Sometimes unsupported should be supported!!! Especially when one needs to go the whole distance to implement such trivial UI requests. The Subgird has all these nice methods that you can use that for some reason Microsoft insist on not exposing as SDK. That’s silly. I would also look for a javascript solution. Here is some pseudo code that can help you with the task. (not tested but it should put you on the right track)

The code creates a simple wrapper on the internal crm grid control and utilizes its methods.

function xGrid(sId) {
    var o = this;
    o.Dom = document.getElementById(sId);

    if (!o.Dom) 
        return alret("this subgrid: " + sId + " is not on the form!");

    o.Grid = o.Dom.contorl;

    o.GetSelectedIds = function () {
            return o.Grid && o.Grid.get_selectedIds();
    }

    o.AddOnSelectionChange = function (fCallback) {
            o.Grid && o.Grid.add_onSelectionChange(fCallback);
            return o;
    }

}

You can create the xGrid when the page loads i.e.

function OnCrmPageLoad() {
    window.MyGrid = new xGrid("SubGrid_Test");
    MyGrid.AddOnSelectionChange(SubGridTestChanged);
}

And call the function bellow then the selection changes

function SubGridTestChanged() {
    if (MyGrid.GetSelectedIds().length > 1)
        alert("You’re only allowed to pick 1 record at a time");
} 



回答2:


A supported way to implement this check is to create a synchrnous plugin on the associate/disassociate message that will check if more than one record is associated and throw and exception, in order to display a warning to the user to select only one record.



来源:https://stackoverflow.com/questions/20656748/subgrid-restrict-user-to-select-only-one-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!