简体   繁体   English

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

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

I have an account entity with a lookup field schoolLookupId which refers back to a custom entity new_schools .我有一个带有查找字段schoolLookupId的帐户实体,它引用回自定义实体new_schools The lookup field only display the name of the school.查找字段仅显示学校名称。 What I would like to be able to do using the onload() event handler of the account form is to run some javascript code that will query the new_phonenumber attribute of the new_schools entity to see if it matches a value i provide lets say var x = "1234" and if it does then update schoolLookupId accordingly with the name of the school that corresponds with the found phone number.我希望能够使用帐户表单的onload()事件处理程序来运行一些 javascript 代码,该代码将查询new_schools实体的new_phonenumber属性,以查看它是否与我提供的值匹配,例如var x = "1234" ,如果确实如此,则使用与找到的电话号码对应的学校名称相应地更新schoolLookupId ie update the lookup field with a phone number that already exists without creating a completely new lookup value.即使用已存在的电话号码更新查找字段,而无需创建全新的查找值。

I can get the attributes of the lookupfield using我可以使用获取查找字段的属性

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

but I can't figure out how to retrieve, compare the data that lies behind the lookup field, and update the lookupfield accordingly.但我不知道如何检索、比较查找字段后面的数据,并相应地更新查找字段。

Your help as always is invaluable.您一如既往的帮助是无价的。

Try put this code in load event:尝试将此代码放在加载事件中:

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

I don't try this code be careful.我不尝试这个代码要小心。 Use this code as a guide.使用此代码作为指南。

Hope this helps.希望这可以帮助。 If i answered your question, please mark the response as an answer and also vote as helpful.如果我回答了您的问题,请将回复标记为答案,并投票为有帮助。

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

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