我创建了以下代码,并将其作为 Web 资源包含在 CRM 2011 表单中,以便在查找字段的字段 onchange 事件中调用。行前一切正常$.ajax({...
,然后出现错误“<code>$ is undefined”。我对脚本不是很熟悉,所以请帮忙。
function GetAddress() {
var accountId;
var dataArray;
var accountRequestUrl;
if (crmForm.all.regardingobjectid.DataValue != null) {
dataArray = crmForm.all.regardingobjectid.DataValue;
accountId = dataArray[0].id;
if (typeof GetGlobalContext == "function") {
var context = GetGlobalContext();
accountRequestUrl = context.getServerUrl();
}
else {
if (typeof Xrm.Page.context == "object") {
accountRequestUrl = Xrm.Page.context.getServerUrl();
}
}
accountRequestUrl = Xrm.Page.context.getServerUrl();
accountRequestUrl += "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'" +
accountId + "')";
crmForm.all.maxlife_addressname.DataValue = accountRequestUrl;
GetAccountRecord(accountRequestUrl);
}
else {
alert("null");
}
}
function GetAccountRecord(accountRequestUrl) {
$.ajax({
type: "GET",
url: accountRequestUrl,
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (request, textStatus, errorThrown) {
alert("Error occurred: " + request.responseXML + "from url " + requestUrl);
return;
},
success: function (data) {
var results = data.d["results"];
var AccountValue = new Array();
for (resultKey in results) {
AccountValue.push(results[resultKey]);
}
FillValues(AccountValue);
}
});
}