在Dynamics 365客户端v9中跨多种表单共享行为

时间:2018-08-23 22:37:37

标签: javascript dynamics-crm microsoft-dynamics dynamics-365 dynamics-crm-365-v9

我正在使用https://github.com/delegateas/XrmDefinitelyTyped。我为具有名为Program YearStart DateEnd Date的字段的表单创建了以下脚本。我希望这是通用的,因此,如果在Form Properties中为ProgramYear设置了一个onChange事件,我可以将其指向TI.Forms.EventHandlers.onProgramYearChange,那么它将执行脚本。

但是,当我传递字段的执行上下文时,就我所知,我无法访问其他属性的执行上下文,并且我看不到任何方法来获取Start Date和{{1 }}。即使我将End Date强制转换为form,也没有定义any函数。解决这个问题的正确方法是什么?

getAttribute

您可以从属性的executionContext访问其他属性吗?

1 个答案:

答案 0 :(得分:0)

  

您可以从属性的executionContext访问其他属性吗?

可以。实际上,当您检查Pass execution context as the first parameter时,CRM会将整个执行上下文传递给事件处理程序。

executionContext.getFormContext()将为您提供整个formcontext,类似于早期的Xrm.Page

这是在表单加载中附加onChange时的工作方式。简洁起见。

var standing = formContext.getAttribute("new_standing");

if (standing !== null) {
    standing.addOnChange(this.validateStatusChanged);
}

下面是本机Web API调用,并从成功回调方法访问formContext。

validateStatusChanged: function (executionContext) {
var formContext = executionContext.getFormContext();

Xrm.WebApi.retrieveMultipleRecords("new_testEntity", query).then(
    function success(result) {
        if (result.entities.length > 0) {
            var limitField = formContext.getAttribute('new_limit');

            if (limitField.getValue() !== 1) {
                limitField.setValue(1);
            }
        }
    },
    function (error) {
        //
    }
);
}