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);
    }
    

      

  • 相关阅读:
    Post提交和Get提交的区别
    Servlet 生命周期
    MVC
    HDU 5033 Building (维护单调栈)
    2014 ACM/ICPC Asia Regional Xi'an Online(HDU 5007 ~ HDU 5017)
    HDU 1026 Ignatius and the Princess I (BFS)
    URAL 1183 Brackets Sequence(DP)
    POJ 3384 Feng Shui(半平面交向内推进求最远点对)
    POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)
    POJ 1279 Art Gallery(半平面交求多边形核的面积)
  • 原文地址:https://www.cnblogs.com/renshaoqun/p/2944786.html
Copyright © 2011-2022 走看看