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
  • 相关阅读:
    linux源码方式安装Apache
    linux的chmod,chown命令详解
    2011年10月18日
    mysql检查查询及索引效率方法(explain)
    php中英文字符串的研究
    2011年10月20日
    PHP JSON中文乱码解决方法大全
    解决PHP下载文件名中文乱码
    php字符串学习笔记
    CSU_BMW正式组队纪念赛出题+部分解题报告
  • 原文地址:https://www.cnblogs.com/dmei/p/13183532.html
Copyright © 2011-2022 走看看