2011-07-07 7 views
0

連絡先の参照を含むフォームがあります。したがって、連絡先のGUID、名前、およびタイプ名を取得できます。GUIDでエンティティの属性を取得する

このコード:

var temp = crmForm.all.to.DataValue; 
alert(temp[0].id + "\n" + temp[0].name + "\n" + temp[0].typename); 

は有効なGUID、名前、およびタイプを返します。

この連絡先の属性(この場合は電話番号)をこの情報でどのように取得できますか?私はこれをフォームのOnLoad関数で実行しようとしているので、これをjavascriptで行う必要があります。

答えて

1

あなたはWebサービス

function GetObjectAttribute(objectid, entityname, attribute) { 
    // Preparer the SOAP message 
    var message = 
     [ 
     "<?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>", 
     "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>", 
     "<entityName>", 
     entityname, 
     "</entityName>", 
     "<id>", 
     objectid, 
     "</id>", 
     "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'", 
     " xsi:type='q1:ColumnSet'>", 
     "<q1:Attributes><q1:Attribute>", 
     attribute, 
     "</q1:Attribute></q1:Attributes>", 
     "</columnSet></Retrieve>", 
     "</soap:Body></soap:Envelope>" 
     ].join(""); 

    var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    xmlhttp.open("POST", "/MSCrmServices/2007/CrmService.asmx", false); 
    xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve"); 
    xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 
    xmlhttp.setRequestHeader("Content-Length", message.length); 
    xmlhttp.send(message); 

    var result = xmlhttp.responseXML; 
    var error = result.selectNodes('//error').length; 
    if (error == 0) { 
     var attributeNode = result.selectSingleNode('//q1:' + attribute); 
     if (attributeNode != null) { 
      return attributeNode.text; 
     } 
    } 
    return null; 
} 

使い方

var fullname = GetObjectAttribute(<GUID>, "Contacts", "fullname"); 
を呼び出すには、次の方法を使用することができます
関連する問題