如何隐藏/显示基于其他选项集CRM Dynamics的选项集

时间:2017-09-06 19:26:16

标签: javascript dynamics-crm microsoft-dynamics dynamics-crm-2016

一个选项集使用正确的选项集定义类别。然后第二个字段仅显示相关选项。但是,当我逐步完成它时,我会不停地进行循环。我创建了一个包含所有正确值的数组并调用它们,但我一直收到错误:

  

TypeError:无法读取属性' toString'未定义的Mscrm.TurboForm.Control.View.PicklistEditElement.addOption(https://ugcrmdev.crm9.dynamics.com/_static/form/formcontrols.js?ver=1659449427:24513:38)"

我不知道自己做错了什么。



var generalServiceRequest = [100000000,100000001,100000002,100000003,100000004,100000005,100000006,100000007,100000008,100000009,100000010,100000011,100000012,100000013,100000014,100000015,100000016,100000017,100000018,100000019,100000020,100000021,100000022,100000023,100000024,100000025,100000026,100000027,100000028,100000029,100000030,100000031,100000032,100000033,100000034,100000035,100000036,100000037,100000038];
var parksAndRec = [100000039,100000040,100000041,100000042,100000043,100000044,100000045];
var boardOfPublicUtilities = [100000046,100000047,100000048,100000049,100000050,100000051];
var publicWorks = [100000052,100000053,100000054,100000055,100000056,100000057,100000058,100000059,100000060,100000061,100000062,100000063,100000064,100000065,100000066,100000067,100000068,100000069,100000070,100000071,100000072,100000073,];
var treasurer = [100000074,100000075,100000076,100000077,100000078,];
var municipalCourt = [100000079,100000080,100000081,100000082,100000083,100000084,100000085,100000086,100000087,];
var districtCourt = [100000088,100000089,100000090,100000091,100000092,100000093,100000094,100000095,];
var neighborHoodResource = [100000096,100000097,100000098,100000099,100000100,100000101,100000102,100000103,100000104,100000105,];
var sheriff = [100000106,100000107,100000108,100000109,100000110,];

//OnLoad of form and OnChange of Specify field.

function masterOptionSet() {

    resetOptionSet();

    var optionValue = Xrm.Page.getAttribute("new_specifyservicerequest").getValue();
    switch (optionValue) {

        case 100000000:
            showOptionSet(generalServiceRequest);
        break;
        case 100000001:
            showOptionSet(parksAndRec);
        break;
        case 100000002:
             showOptionSet(boardOfPublicUtilities);
        break;
        case 100000003:
             showOptionSet(publicWorks);
        break;
        case 100000004:
            showOptionSet(treasurer);
        break;
        case 100000005:
            showOptionSet(municipalCourt);
        break;
        case 100000006:
            showOptionSet(districtCourt);
        break;
        case 100000007:
            showOptionSet(neighborHoodResource);
        break;
        case 100000008:
            showOptionSet(sheriff);           
    }
}

function resetOptionSet()
{   
    for(var i = 100000000; i <= 100000110; i++){

        Xrm.Page.getControl("new_subjectmatter").removeOption(i);
    }
}

function showOptionSet(optionArray){
    for(var i = 0; i< optionArray.length; i++){
        Xrm.Page.getControl("new_subjectmatter").addOption(optionArray[i]);
    }   
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

选项列表选项是键值对。应该像下面一样添加选项:

(可能你可能需要保留多维数组才能存储正确的值)

var sheriff = { value : 100000000 , text : "sheriff123" };

var picklist = Xrm.Page.getControl("new_subjectmatter");
var options = picklist.getOptions();

function resetOptionSet()
{   
    for(var i = 0; i < options.length; i++){
        Xrm.Page.getControl("new_subjectmatter").removeOption(options[i].value);
    }
}

function showOptionSet(optionArray){
    for(var i = 0; i< optionArray.length; i++){
        Xrm.Page.getControl("new_subjectmatter").addOption(optionArray[i]);
    }   
}

另外,请考虑resetOptionSet()方法中的上述更改,以包含动态选项列表,而不是硬编码。

如果您想尝试,

Another approach是一个不错的选择,对于依赖选项集的配置实体,生活将更容易。