zoukankan      html  css  js  c++  java
  • Dynamics 365 选项集字段显示指定值(单选项集)

    在项目中,经常会碰到,选项集字段显示值会根据其它字段控制联动。比如:未提交状态,只显示1,2;已提交状态,显示3,4...

    1.调用示例

    if (machinetype == 1) {
            ShowOption("new_returntype", [1, 2]);
        } else if (machinetype == 2) {
            ShowOption("new_returntype", [1, 2]);
        } else if (machinetype == 3) {
            ShowOption("new_returntype", [1]);
        } else if (machinetype == 4) {
            ShowOption("new_returntype", [2, 5]);
        } else {
            ShowOption("new_returntype", [2]);
        }

    2. ShowOption方法如下

    function ShowOption(field, filterArray) {
        /// <summary>选项集显示指定值(选项集值)</summary>
        /// <param name="filterArray">显示值:[1,2,3]</param>
        let optionsetControl = Xrm.Page.getControl(field);  // OptionSet 的选项对象
        if (optionsetControl != undefined && optionsetControl != null) {
            let options = optionsetControl.getAttribute().getOptions(); // 获取选项所有对象值
            let currentValue = Xrm.Page.getAttribute(field).getValue()
            optionsetControl.clearOptions();  // 从选项集控件清除所有选项
            options.forEach(function (item) {
                let isIn;
                if (this.isIExplorer()) {
                    isIn = (filterArray.indexOf(item.value) != -1);
                } else {
                    isIn = filterArray.includes(item.value);
                }
                if (isIn === true) {
                    optionsetControl.addOption(item);
                }
            });
    
            //  默认值重新赋值
            if (currentValue) {
                Xrm.Page.getAttribute(field).setValue(currentValue);
            }
        }
    }
    View Code
  • 相关阅读:
    菜鸡学习之路之并查集
    Leetcode 28. 实现 strStr() python3
    Leedcode 67. 二进制求和 python3
    2020 高校战“疫”网络安全分享赛 misc ez_mem&dump & 隐藏的信息
    leetcode 709.转换成小写字母
    2020 MetasequoiaCTF 部分misc
    Linux任务在后台运行
    Linux网络监控(netstat)
    Linux中wget资源下载
    Linux远程登录+远程发送文件
  • 原文地址:https://www.cnblogs.com/dmei/p/13183532.html
Copyright © 2011-2022 走看看