简体   繁体   English

将模块附加到Microsoft Dynamics CRM表单事件

[英]Attaching modules to Microsoft Dynamics CRM Form Events

I am using Typescript to write custom code to handle form events. 我正在使用Typescript编写自定义代码来处理表单事件。 For each form, I have a separate file and then I combine the files at compile time into one file that I then use across all forms. 对于每种形式,我都有一个单独的文件,然后在编译时将这些文件合并为一个文件,然后将其用于所有形式。 I am having trouble attaching events to the form - I get an error that my function name can't be found. 我在将事件附加到表单时遇到麻烦-我收到找不到我的函数名称的错误。 Below is one of the requirejs modules that is in the compiled Javascript file. 以下是已编译的Javascript文件中的requirejs模块之一。 I have tried connecting the events using Evaluation.[function] , Forms/Evaluation.[function] , and EvaluationScripts.[function] without any luck. 我尝试使用Evaluation.[function]Forms/Evaluation.[function]EvaluationScripts.[function]连接事件,但没有任何运气。 What naming structure should I be using to attach my form events? 我应该使用什么命名结构来附加表单事件?

tsc compile tsc编译

define("Forms/Evaluation", ["require", "exports", "Global/Helpers", "Global/CCSEQ", "Global/Sync", "Global/Util", "Global/Query"], function (require, exports, Helpers, CCSEQ, Sync_4, Util_10, Query) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var EvaluationScripts = (function (_super) {
__extends(EvaluationScripts, _super);
function EvaluationScripts() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.EmployeeStaffLevelAsOfDateQuery = //query;
return _this;
}
EvaluationScripts.prototype.onLoad = function () {

};
EvaluationScripts.prototype.onSave = function (execObj) {

};
EvaluationScripts.prototype.ccseq_employeeid_onChange = function () {

};

return EvaluationScripts;
}(Helpers.FormLibrary));
exports.Evaluation = new EvaluationScripts();
});

Update 更新

I have tried to use Webpack to compile my modules as well, but I am still getting an error when I connect the onLoad function to the onLoad event. 我也尝试使用Webpack编译模块,但是将onLoad函数连接到onLoad事件时仍然出现错误。 Below is an example of my Webpack-compiled file. 以下是我的Webpack编译文件的示例。

Webpack-Compile 的WebPack编译

var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(6)], __WEBPACK_AMD_DEFINE_RESULT__ = function (require, exports, EvaluationForm) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Evaluation = EvaluationForm;
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
                __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));


/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {

var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(7), __webpack_require__(1), __webpack_require__(4), __webpack_require__(0), __webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = function (require, exports, Helpers, CCSEQ, Sync_1, Util_1, Query) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var evaluationPeriodDate;
    var EmployeeStaffLevelAsOfDateQuery = xml;
    function onLoad() {

    }
    exports.onLoad = onLoad;
    function onSave(execObj) {

    }
    exports.onSave = onSave;
    function onCreate() {

    }
    exports.onCreate = onCreate;
    function ccseq_employeeid_onChange() {

    }
    exports.ccseq_employeeid_onChange = ccseq_employeeid_onChange;

}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
                __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));

The issue is not with webpack. 问题不是webpack。 The issue is the function is not being set to the global scope. 问题是该函数未设置为全局范围。

The simplest way to add the function globally is 全局添加功能的最简单方法是

window.Evaluation = new EvaluationScripts(); window.Evaluation =新的EvaluationScripts();

I think you may be slightly complicating thing trying to use WebPack. 我认为您尝试使用WebPack可能会使事情变得有些复杂。
I use TypeScript for all my CRM JavaScript and the pattern I use is to create a ts file for every entity that looks like: 我将TypeScript用于所有我的CRM JavaScript,并且使用的模式是为每个如下所示的实体创建一个ts文件:

/// <reference path="../type definations/xrm.d.ts" />
/// <reference path="../type definations/jquery.d.ts" />

namespace xrm.entities.contact {

    class FormScripts {
        constructor() {
            //
        }

        private _onLoad() {

        }


        public OnLoad() {
            this._onLoad();
        }
    };

    //Expose the same js interface as the legacy code
    export var code;
    code = new FormScripts();
}

My OnLoad handler in CRM for the contact entity then looks like: 然后,我在CRM中用于联系人实体的OnLoad处理程序如下所示:

xrm.entities.contact.code.OnLoad

We use gulp to merge all the referenced libraries in to a single javascript file that can be uploaded to CRM as a single webresource 我们使用gulp将所有引用的库合并到单个javascript文件中,该文件可以作为单个Web资源上载到CRM

In the end, I ended up creating a new file that imported all of the Form files. 最后,我最终创建了一个导入所有Form文件的新文件。 This, along with rexkenley's suggestion allowed me to connect the form events successfully using CCSEQ.[FormName] . 这以及rexkenley的建议使我能够使用CCSEQ.[FormName]成功连接表单事件。

Library.ts Library.ts

import {Test as TestForm} from './path/to/form';

(<any>window).CCSEQ = {};

(<any>window).CCSEQ.Test = TestForm;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM