我正在使用https://github.com/delegateas/XrmDefinitelyTyped。我为具有名为Program Year
,Start Date
,End Date
的字段的表单创建了以下脚本。我希望这是通用的,因此,如果在Form Properties中为ProgramYear设置了一个onChange
事件,我可以将其指向TI.Forms.EventHandlers.onProgramYearChange
,那么它将执行脚本。
但是,当我传递字段的执行上下文时,就我所知,我无法访问其他属性的执行上下文,并且我看不到任何方法来获取Start Date
和{{1 }}。即使我将End Date
强制转换为form
,也没有定义any
函数。解决这个问题的正确方法是什么?
getAttribute
您可以从属性的executionContext访问其他属性吗?
答案 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) {
//
}
);
}