我一直在关注 HTML webresource,我需要获取联系人 ID,然后做剩下的事情。它提示我有 1 个针对该特定电话号码的联系人,但它在 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>