使用 XRMServiceToolkit 在 HTML Web 资源中使用手机号码检索联系人

Retreive Contacts Using Mobile Number in an HTML Webresource using XRMServiceToolkit

我已经在关注 HTML 网络资源,我需要获取联系人 ID,然后再做其他事情。它提示我我有 1 个联系人针对那个特定的 phone 号码,但它在 retreivedContact 处抛出异常(在 javascript 之后是可变的)。当我过去检查 mobileNumber 时,调试器也说它未定义。能否请您看看并告诉我是什么东西弄乱了:

    <!DOCTYPE html>
<html>
<head>
    <title>Contacts</title>
    <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
    <script type="text/javascript" src="../WebResources/new_jquery_1.9.1.min" ></script>
    <script type="text/javascript" src="../WebResources/new_xrmjson" ></script>
    <script type="text/javascript" src="../WebResources/new_xrmservicetoolkit" ></script>
    <script type="text/javascript">
        function getLoggedInUserRoles() {
            try {
                debugger;
            var context = GetGlobalContext();
            var mobileNumber = "xxx-xxx-xxx";
            if (mobileNumber.length > 0) {
                    var query = "<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 type='and'>" +
                        "      <condition attribute='mobilephone' operator='eq' value='" + mobileNumber + "'/>" +
                        "    </filter>" +
                        "  </entity>" +
                        "</fetch>";

                    var retreivedContacts = XrmServiceToolkit.Soap.Fetch(query);

                    if (retreivedContacts.length == 1) {
                        alert(retreivedContacts.length);
                        alert(retreivedContacts[0].attributes['contactid']);
                        //Xrm.Utility.openEntityForm("contact", retreivedContacts[0].attributes['contactid'])
                    }
                }
            } catch (e) {
            alert("Error: "+e.Message);
            }
    }
    </script>
</head>
<body>  
    <button onclick="getLoggedInUserRoles()">Click here</button>
</body>
</html>

已解决,我更改以下代码段

alert(retreivedContacts[0].attributes['contactid']);

alert(retreivedContacts[0].attributes['contactid'].value);