繁体   English   中英

动态 crm 4.0 查找字段 onload() 查询

[英]dynamics crm 4.0 lookup field onload() query

我有一个带有查找字段schoolLookupId的帐户实体,它引用回自定义实体new_schools 查找字段仅显示学校名称。 我希望能够使用帐户表单的onload()事件处理程序来运行一些 javascript 代码,该代码将查询new_schools实体的new_phonenumber属性,以查看它是否与我提供的值匹配,例如var x = "1234" ,如果确实如此,则使用与找到的电话号码对应的学校名称相应地更新schoolLookupId 即使用已存在的电话号码更新查找字段,而无需创建全新的查找值。

我可以使用获取查找字段的属性

var name = crmForm.all.schoolLookupid.DataValue[0].name
var id = crmForm.all.schoolLookupid.DataValue[0].id
var typename = crmForm.all.schoolLookupid.DataValue[0].typename

但我不知道如何检索、比较查找字段后面的数据,并相应地更新查找字段。

您一如既往的帮助是无价的。

尝试将此代码放在加载事件中:

   var xml = "" +  
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +  
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +  
    GenerateAuthenticationHeader() +  
    " <soap:Body>" +  
    " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +  
    " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +  
    "        <q1:EntityName>new_schools</q1:EntityName>" + 
    "        <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "          <q1:Attributes>" + 
    "            <q1:Attribute>new_schoolsid</q1:Attribute>" + 
    "          </q1:Attributes>" + 
    "        </q1:ColumnSet>" + 
    "        <q1:Distinct>false</q1:Distinct>" + 
    "        <q1:Criteria>" + 
    "          <q1:FilterOperator>And</q1:FilterOperator>" + 
    "          <q1:Conditions>" + 
    "            <q1:Condition>" + 
    "              <q1:AttributeName>new_phonenumber</q1:AttributeName>" + 
    "              <q1:Operator>Equal</q1:Operator>" + 
    "              <q1:Values>" + 
    "                <q1:Value xsi:type=\"xsd:string\">"+crmForm.all.new_phonenumber.DataValue+"</q1:Value>" + 
    "              </q1:Values>" + 
    "            </q1:Condition>" +
    "          </q1:Conditions>" + 
    "        </q1:Criteria>" + 
    " </query>" +  
    " </RetrieveMultiple>" +  
    " </soap:Body>" +  
    "</soap:Envelope>" +  
    "";  

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttpRequest.Open("POST", "http://"+window.location.hostname+":"+window.location.port+"/mscrmservices/2007/crmservice.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction"," http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");  
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");  
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);  
    xmlHttpRequest.send(xml);  

    var resultXml = xmlHttpRequest.responseXML;

    if (_resultXml.xml.search('<q1:new_schoolsid')>0)
    {
        var val = xmlDoc.getElementsByTagName("q1:new_schoolsid")[0].childNodes[0].nodeValue;

        var lookupitem = new Array(); 
        lookupitem[0] = new LookupControlItem(val , typecode, name); 
        crmForm.all.schoolLookupid.DataValue = lookupitem ; 
    }
}

我不尝试这个代码要小心。 使用此代码作为指南。

希望这可以帮助。 如果我回答了您的问题,请将回复标记为答案,并投票为有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM