【问题标题】:Retrieving an entity's attributes by GUID通过 GUID 检索实体的属性
【发布时间】:2011-07-07 15:07:42
【问题描述】:

我有一个包含联系人查找的表单。因此我可以获得联系人的 guid、姓名和类型名。

这段代码:

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

返回有效的 guid、名称和类型。

如何使用此信息获取此联系人的属性(本例中为电话号码)?我正在尝试在表单的 OnLoad 函数中执行此操作,因此我需要在 javascript 中执行此操作。

【问题讨论】:

    标签: javascript dynamics-crm dynamics-crm-4


    【解决方案1】:

    您可以使用以下方法调用webservices

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多