您需要调用 CRM 网络服务来检索电话号码,您可以使用此功能(如果您的查找指向系统用户,这将起作用)
function getPhoneNumberBySystemUserId(userId) {
var serverUrl;
if (Xrm.Page.context.getClientUrl !== undefined) {
serverUrl = Xrm.Page.context.getClientUrl();
} else {
serverUrl = Xrm.Page.context.getServerUrl();
}
// build the request
var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var userRequest = new XMLHttpRequest();
userRequest.open("GET", ODataPath + "/SystemUserSet(guid'" + userId + "')", false);
userRequest.setRequestHeader("Accept", "application/json");
userRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
// execute the request
userRequest.send();
if (userRequest.status === 200) {
var retrievedUser = JSON.parse(userRequest.responseText).d;
// retrieve the phone number of the user
var phonenumber = retrievedUser.Address1_Telephone1; // change to MobilePhone to get the mobile phone, to HomePhone to get the home phone
return phonenumber;
} else {
return "error";
}
}
并使用您的代码,您可以以这种方式使用:
var lookupObject = Xrm.Page.getAttribute("new_accountmanager0");
var lookUpObjectValue = lookupObject.getValue();
if (lookUpObjectValue != null) {
var phonenumber = getPhoneNumberBySystemUserId(lookUpObjectValue[0].id);
alert(phonenumber);
}