CRM 2011“$ 未定义”
我创建了以下代码,并将其作为 Web 资源包含在 CRM 2011 表单上,以便在查找字段的字段 onchange 事件上调用。在 $.ajax({...
行之前一切正常,然后出现错误“$
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);
}
});
}
I have created following code, and I have included this as web resource on the CRM 2011 form to be called on field onchange event of lookup field. Everything is working fine before the $.ajax({...
line and then I have an error “$
is undefined”.
I am not very familiar with scripting so please help.
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);
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
$ 是 jQuery 的简写。 jQuery 本身并不包含在 CRM2011 中,因此您必须自己添加 Web 引用。只需为 jQuery 创建一个 JavaScript Web 资源,粘贴 jQuery 代码,然后将该 Web 资源添加到您的表单中。此外,为了将 Web 资源加载到您的表单上,您需要指定 CRM 从中调用的函数。由于在本例中 jQuery 是一个库,并且您不会在 onload 上调用它的任何函数,因此只需使用 isNaN(原生 JavaScript 函数)作为要调用的函数即可。
$ is shorthand for jQuery. jQuery is not natively included in CRM2011, so you'll have to add a web reference yourself. Simply create a JavaScript web resource for jQuery, paste in the jQuery code, and then add the web resource to your form. Also, in order to get the web resource to load on your form, you need to specify a function for CRM to call from it. Since in this case jQuery is a library and you won't be calling any of its functions onload, simply use isNaN (a native JavaScript function) as the function to call.
您正在处理的实体表单。转到表单定制->表单属性。
您可以看到该表单已包含的文件(.js)。
如果您的 CRM Web 资源中添加了 JQuery 文件,请单击“添加”(左上方)...并添加 JQuery 文件(如 JQuery1.4.4 或更高版本),如果没有,则需要先将此文件添加到 CRM Web 资源中。
The entity form on which you are working. Go to Form customization->Form properties.
You can see the Files(.js) already included for that form.
Click on 'Add'(left top)..and add the JQuery file(like JQuery1.4.4 or higher version) if JQuery file is added in your CRM Webresources, if not then you need to add this file in CRM webresources first.
听起来您需要在表单中包含 jquery。
基本上,您只需添加 jquery,就像添加任何其他 javascript 文件一样。
将新创建的 Web 资源添加到表单(在“表单属性”下)。
确保这是您表单上列出的第一个图书馆。
您不需要 jquery 事件处理程序中的任何内容,只需像往常一样从任何自定义库中调用它即可。
请记住,您可能想使用 jquery 完成的许多事情可能不受支持。 Microsoft 希望您使用 Xrm.Page 对象:
使用 Xrm.Page 对象模型
http://msdn.microsoft.com/en-us/library/gg328474.aspx
将 REST 端点与 Ajax 和 JScript Web 资源结合使用
http://msdn.microsoft.com/en -us/library/1bb82714-1bd6-4ea4-8faf-93bf29cabaad#BKMK_UsingJQuery
CRM 2011 有用的 JavaScript 花絮
调用字段的onchange事件
http://www.powerobjects.com/博客/2011/01/14/crm-2011-useful-javascript-tidbits/
Sounds like you need to include jquery on your form.
Basically you just add jquery the same way you would any other javascript file.
Add your newly created Web Resource to your form (Under Form Properties).
Be sure this is the first library listed on your form.
You don’t need anything in Event Handlers for jquery, just call it from any of your custom libraries as per usual.
Keep in mind that many of the things you may be tempted to use jquery for may not be supported. Microsoft wants you to use the Xrm.Page object:
Use the Xrm.Page Object Model
http://msdn.microsoft.com/en-us/library/gg328474.aspx
Use the REST Endpoint with Ajax and JScript Web Resources
http://msdn.microsoft.com/en-us/library/1bb82714-1bd6-4ea4-8faf-93bf29cabaad#BKMK_UsingJQuery
CRM 2011 Useful JavaScript Tidbits
Call the onchange event of a field
http://www.powerobjects.com/blog/2011/01/14/crm-2011-useful-javascript-tidbits/