代码之家  ›  专栏  ›  技术社区  ›  Tim Hutchison

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

  •  0
  • Tim Hutchison  · 技术社区  · 8 年前

    我使用Typescript编写自定义代码来处理表单事件。对于每个表单,我都有一个单独的文件,然后在编译时将这些文件合并成一个文件,然后在所有表单中使用。我在将事件附加到表单时遇到问题-我遇到了一个错误,无法找到我的函数名。下面是编译的Javascript文件中的一个requirejs模块。我尝试使用连接事件 Evaluation.[function] , Forms/Evaluation.[function] EvaluationScripts.[function]

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

    使现代化

    onLoad 功能 空载 事件下面是我的网页包编译文件的示例。

    网页包编译

    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__));
    
    3 回复  |  直到 8 年前
        1
  •  1
  •   rexkenley    8 年前

    全局添加函数的最简单方法是

    窗评估=新评估脚本();

        2
  •  0
  •   Malachy    8 年前

    我认为你们使用WebPack可能有点复杂。
    我对所有CRM JavaScript都使用TypeScript,我使用的模式是为每个实体创建一个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();
    }
    

    然后,CRM中联系人实体的OnLoad处理程序如下所示:

    xrm.entities.contact.code.OnLoad
    

    我们使用gulp将所有引用的库合并到单个javascript文件中,该文件可以作为单个webresource上传到CRM

        3
  •  0
  •   Community Mohan Dere    5 年前

    最后,我创建了一个新文件,导入了所有表单文件。这一点,再加上雷克斯·肯利的建议,使我能够使用 CCSEQ.[FormName] .

    图书馆输电系统

    import {Test as TestForm} from './path/to/form';
    
    (<any>window).CCSEQ = {};
    
    (<any>window).CCSEQ.Test = TestForm;
    
    推荐文章