Xrm在Dynamics CRM 2011中未定义

Ste*_*eve 4 dynamics-crm-2011

当我创建.js代码时,我似乎无法使我的Xrm变量工作.是否需要包含一个库或我需要先运行的函数?我是否需要确保正确引用ClientGlobalContext.js.aspx?我处于'C++'的思维模式中,只是想知道我是否需要运行任何类型的'include'命令.

我的js文件看起来像这样,如果我删除'window.parent'.从第二个函数开始,如果我调用它,代码就会中断.

///<reference path="C:\Users\steve.lee\Downloads\XrmPage-vsdoc.js"/>

if (typeof (SDK) == "undefined") 
{ SDK = { __namespace: true }; }

SDK.XRM = {
    getCurrentControl: function () {
        var currentControl = Xrm.Page.ui.getCurrentControl();
        if (currentControl == null) {
            alert("No controls currently have focus.");
        }
        else {
            alert("The control for the '" + currentControl.getLabel() + "' attribute currently has focus.");
        }
    },

    getCurrentGUID: function () {

        if (window.parent.Xrm.Page.data.entity != null) {
            var GUIDvalue = window.parent.Xrm.Page.data.entity.getId();
            if (GUIDvalue != null) {
                return GUIDvalue;
            }
            else {
                return null;
            }
        }
        else {
            return null;
        }
    },
 __namespace: true
};
Run Code Online (Sandbox Code Playgroud)

Chr*_*ris 9

您的代码是作为添加到表单的JavaScript库运行还是位于Web资源中?

如果是后者,则需要window.parent(如果是HTML Web资源).这样可以访问表单上的Xrm对象.在它上面的窗口中.

如果它是附加到表单属性的javascript库,则默认情况下XRM对象可用.

如果您的Web资源可能不在表单的上下文中,并且仍然允许您访问服务器URL和登录用户,则使用ClientGlobalContext.js.aspx.