Hey all,
I have the following code which will lock all fields on the selected row of an editable subgrid - this works fine:
function onGridRowSelected(context){
context.
getFormContext().
getData().
getEntity().
attributes.
forEach(function (attr) {
attr.controls.forEach(function (myField) {
myField.setDisabled(true);
});
});
}
When I try to call this function from the response of an async function, nothing happens (my breakpoint shows that it is setting the control to locked, yet it does not happen on the form).
In the below code, I fetch a row using retrieveMultipleRecords(). I await this in an async function and use the return of the Promise to call my setFieldLockedProperty() function.
var gridContext;
function onGridRowSelected(context){
gridContext = context.getFormContext();
Xrm.WebApi.retrieveMultipleRecords("ms_approvalquery", "?$select=ms_responsetext&$top=1&$orderby=createdon desc")
.then(result => lockOrUnlock(result));
}
function lockOrUnlock(result){
var foundResponse = false
if (result.entities[0].pa_responsetext != null){
foundResponse = true;
}
gridContext.data.entity.attributes.forEach(function (attr) {
attr.controls.forEach(function (myField) {
myField.setDisabled(foundResponse);
})
});
}
Could someone please explain why control.setDisabled() will not work if done on an async thread? Are there any workarounds for this? I've refactored my code several time to try different methods however I have come to a dead end.
Thanks!