在实体表单中嵌入高级查找视图(Crm 2011)

时间:2013-05-21 16:38:38

标签: javascript dynamics-crm-2011

我们使系统根据用户指定的“获取XML”在记录列表上工作。 (简单的FetchXml字段)

为了方便起见,我们想要一个很好的用户界面来编辑'获取XML'。

我们看到了this解决方案 - 但它适用于CRM 4。

CRM 2011有什么相似之处吗?

3 个答案:

答案 0 :(得分:1)

// JavaScript source code
function SearchCustomers() {

    var params = '';   

    var fullname = Xrm.Page.getAttribute("fullname").getValue();
    if (fullname != null) {
        params += "fullname" + GetParam(fullname);        
    }    
    var IFrame = Xrm.Page.ui.controls.get("IFRAME_advancedfind");

    var url = getServerUrl() + "/WebResources/new_advancedfind.htm?Data=" + params;
    IFrame.setSrc(url);
}

function GetParam(data) {
    return "%3D" + encodeURIComponent(data) + "%26";
}
function getServerUrl() {
    //var context = GetGlobalContext();
    //var serverUrl = context.getClientUrl();
    var serverUrl = window.location.protocol + "//" + window.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
    if (serverUrl.match(/\/$/)) {
        serverUrl = serverUrl.substring(0, serverUrl.length - 1);
    }
    return serverUrl;
}

// new_advancedfind.htm Webresource

<HTML><HEAD><TITLE></TITLE>
<SCRIPT type=text/javascript src="ClientGlobalContext.js.aspx"></SCRIPT>
<SCRIPT type=text/javascript>    

    function submitForm() {

        var fullname = "";
        var vals = getDataParam();
        fullname = GetParam(vals, 'fullname');

        var filter = '<filter type="and"> <condition attribute="fullname" value="%' + fullname + '%" operator="like"/> <condition attribute="statecode" value="0" operator="eq"/> </filter>';
        var fetch = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="contact"><attribute name="fullname"/><attribute name="telephone1"/><attribute name="contactid"/><order attribute="fullname" descending="false"/>' + filter + '</entity></fetch>';
        var form = document.getElementById("AdvancedFind");

        form.action = getServerUrl() + '/AdvancedFind/fetchData.aspx';
        form.LayoutXml.value = '<grid name="resultset" object="2" jump="lastname" select="1" icon="1" preview="1"><row name="result" id="contactid"><cell name="fullname" width="300" /><cell name="telephone1" width="125" /></row></grid>';

        form.FetchXml.value = fetch;
        form.submit();
    }
function getServerUrl() {
    //var context = GetGlobalContext();
    //var serverUrl = context.getClientUrl();
    var serverUrl = window.location.protocol + "//" + window.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
    if (serverUrl.match(/\/$/)) {
        serverUrl = serverUrl.substring(0, serverUrl.length - 1);
    }
    return serverUrl;
}
function getDataParam() {

    //Get the any query string parameters and load them
    //into the vals array
    var RetVals = new Array();
    var vals = new Array();
    if (location.search != "") {
        vals = location.search.substr(1).split("&");
        for (var prmCounter = 0; prmCounter < vals.length; prmCounter++) {
            vals[prmCounter] = vals[prmCounter].replace(/\+/g, " ").split("=");
        }
        //look for the parameter named 'data'
        var found = false;
        for (var _prmCounter = 0; _prmCounter < vals.length; _prmCounter++) {
            if (vals[_prmCounter][0].toLowerCase() == "data") {
                RetVals = parseDataValue(vals[_prmCounter][1]);
            }
        }

    }
    return RetVals;
}

function parseDataValue(datavalue) {
    if (datavalue != "") {
        return decodeURIComponent(datavalue).split("&");
    }
}
function GetParam(vals, attribute) {
    var val = '';
    var found = false;
    for (i = 0; i < vals.length && !found; i++) {
        if (vals[i].indexOf(attribute) > -1) {
            val = vals[i].split('=')[1];
            found = true;
            break;
        }
    }
    return val;
}
</SCRIPT>
<META charset=utf-8></HEAD>
<BODY onload=submitForm()>
<FORM id="AdvancedFind" method="post" action="">
<INPUT name=FetchXml type=hidden> 
<INPUT name=LayoutXml type=hidden> 
<INPUT name=EntityName value=contact type=hidden> 
    <!--Replace DefaultAdvFindViewId valu to contact's default advanced find view Guid-->
<INPUT name=DefaultAdvFindViewId value={00000000-0000-0000-00AA-000000666400} type=hidden> 
<INPUT name=ViewId value={00000000-0000-0000-00AA-000000666400} type=hidden> 
<INPUT name=ViewType value=4230 type=hidden> 
<INPUT name=SortCol value=fullname:1; type=hidden> 
<INPUT name=UIProvider type=hidden> 
<INPUT name=DataProvider type=hidden> </FORM></BODY></HTML>

答案 1 :(得分:0)

我还没有尝试过这个(但是)但我认为应该可以使用URL addressable views(以支持的方式)这样做。以某种方式在CRM中创建视图(例如,使用adv查找之前手动创建)或使用JS动态创建它。然后应该可以“调用”上面每个链接的视图。

免责声明:这是所有理论。如果你得到了一些有用的东西,请告诉我们。

答案 2 :(得分:0)

是的,我在Dynamics CRM 2011上做过,它正在进行所有部署,在线/ OnPremise和托管(IFD),

  1. 创建一个Javascript网络资源,然后创建您的FetchXML,然后发送到自定义高级查找网络资源。
  2. 为显示高级查找网格创建一个Html网络资源,为所有实体执行创建的动态FetchXml。