I am using https://github.com/delegateas/XrmDefinitelyTyped. I created the following script for a form that has a field called Program Year
, Start Date
, End Date
. I would like this to be generic so that if in the Form Properties I set an onChange
event for ProgramYear I can point it to TI.Forms.EventHandlers.onProgramYearChange
then it will execute the script.
However, when I pass the field's execution context I cannot access the execution context of the other attributes as far as I know and I don't see any ways to get the other attributes of Start Date
and End Date
. Even if I cast form
to any
there is no getAttribute
function defined. What is the correct way to approach this?
namespace TI.Forms.EventHandlers {
export function onProgramYearChange(executionContext: Xrm.ExecutionContext<any>) {
var form = executionContext.getFormContext();
form.getAttribute("ti_programyear").addOnChange((context) => {
const updatedProgramYear = context.getEventSource().getValue()[0].name;
XrmQuery.retrieveMultiple(x => x.ti_program_years)
.select(x => [x.ti_start_date, x.ti_end_date])
.filter(x => Filter.equals(x.ti_name, updatedProgramYear))
.execute(programYears => {
const startDateField = form.getAttribute("ti_start_date");
const endDateField = form.getAttribute("ti_end_date");
if (!startDateField.getValue() && !endDateField.getValue()) {
startDateField.setValue(programYears[0].ti_start_date);
endDateField.setValue(programYears[0].ti_end_date);
}
});
});
}
}
Can you access other attributes from the executionContext of an attribute?