zoukankan      html  css  js  c++  java
  • Dynamics CRM 2011 Lookup类型字段实现多选及保存、显示

    1.把lookup类型的字段单选变为多选代码:

    document.getElementById("new_account").setAttribute("lookupstyle", "multi");
    

    2.需要新建一个文本字段来存储多选产生的值,因为Lookup虽然能实现多选,但不能保存多个选项的值。保存后通过JS把多选的值以XML形式存入文本,显示时再从文本取值处理后给Lookup赋值。

    //实例:多选Lookup字段new_account 、文本类型字段new_txtxml
    function formOnload() {
     document.getElementById("new_account").setAttribute("lookupstyle", "multi");
     getarrfromxml();    
    }
    function formOnsave() {    
        PartyListSave("new_account", "new_txtxml");
      }
    //解析xml为数组,赋值给lookup类型字段
    function getarrfromxml() {   
        if (Xrm.Page.ui.getFormType() != 1) {
            var contentXml = Xrm.Page.getAttribute("new_txtxml").getValue();
            if (contentXml != null) {
                var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.loadXML(contentXml);
                var value = new Array();
                var nodeList = xmlDoc.getElementsByTagName("li");
                for (var i = 0; i < nodeList.length; i++) {
                    value[i] = new Object();
                    value[i].id = nodeList[i].getAttribute("oid");
                    value[i].name = nodeList[i].getAttribute("title");
                    value[i].typename = nodeList[i].getAttribute("otypename");
                }
                crmForm.all["new_account"].DataValue = value;
            }
        }
    }
    function PartyListSave(textControl, multiTextControl) {
        var url = window.location.host;
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.loadXML("<r></r>");
        var root = xmlDoc.firstChild;
        var tbl = document.getElementById(textControl + "_d").firstChild;
        var div = tbl.rows[0].cells[0].firstChild;
        var ul = div.childNodes[0];
        var targetObject = Xrm.Page.getAttribute(textControl);
        var targetObjectContent = Xrm.Page.getAttribute(multiTextControl);
        root.setAttribute("tabIndex", div.tabIndex);
        for (var i = 0; i < ul.childNodes.length; i++) {
            var uNode = root.appendChild(xmlDoc.createElement("li"));
            uNode.setAttribute("title", ul.childNodes[i].firstChild.getAttribute("title"));
            uNode.setAttribute("otypename", ul.childNodes[i].firstChild.getAttribute("otypename"));
            uNode.setAttribute("otype", ul.childNodes[i].firstChild.getAttribute("otype"));
            uNode.setAttribute("oid", ul.childNodes[i].firstChild.getAttribute("oid"));
            uNode.setAttribute("src", ul.childNodes[i].firstChild.firstChild.firstChild.src.replace("http://" + url, ""));
        }
        targetObjectContent.setValue(xmlDoc.xml);
        targetObject.setValue(null);
    }
    

      

  • 相关阅读:
    分页查询
    web 开发中 405报错
    html 中input标签的name属性
    怎么样利用debug
    bzoj 1314: River过河 优先队列
    bzoj 4004: [JLOI2015]装备购买 拟阵 && 高消
    bzoj 1133: [POI2009]Kon dp
    bzoj 4127: Abs 树链剖分
    bzoj 2406: 矩阵 上下界网络流判定
    再写FFT模板
  • 原文地址:https://www.cnblogs.com/renshaoqun/p/2944786.html
Copyright © 2011-2022 走看看