CRM 2011“$未定义” [英] CRM 2011 "$ is undefined"

查看:130
本文介绍了CRM 2011“$未定义”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了以下代码,并将其作为Web资源包含在CRM 2011表单中,以便在查找字段的字段onchange事件上调用。在 $。ajax({... 行,然后我有错误 $ 之前,一切正常undefined。
我不太熟悉脚本,所以请帮忙。

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);
        }
    });
}


推荐答案

$是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.

这篇关于CRM 2011“$未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆