I am using the Power Apps grid control which allows a record's child records to be edited. The aim is set the quarter fields to read only depending if the quarter has been locked for editing. Ideally, I wanted to use the quarter lock field from the parent entity and add that to the grid to be picked up by the JavaScript but I could not get it to work. I had to resort to adding the same quarter lock field to the child entity and use a flow to update the record. Below is the code I have added in...
function lockQuarterActualsOnGrid(executionContext) {
let gridContext = executionContext.getFormContext();
//Get quarter controls
let q1 = gridContext.getAttribute('sa_q1');
let q2 = gridContext.getAttribute('sa_q2');
let q3 = gridContext.getAttribute('sa_q3');
let q4 = gridContext.getAttribute('sa_q4');
//Get quarter locks
let q1Locked = gridContext.getAttribute('sa_q1locked').getValue();
let q2Locked = gridContext.getAttribute('sa_q2locked').getValue();
let q3Locked = gridContext.getAttribute('sa_q3locked').getValue();
let q4Locked = gridContext.getAttribute('sa_q4locked').getValue();
//Lock each quarter as necessary
if (q1Locked) {
q1.controls.get(0).setDisabled(true);
}
else {
q1.controls.get(0).setDisabled(false);
}
if (q2Locked) {
q2.controls.get(0).setDisabled(true);
}
else {
q2.controls.get(0).setDisabled(false);
}
if (q3Locked) {
q3.controls.get(0).setDisabled(true);
}
else {
q3.controls.get(0).setDisabled(false);
}
if (q4Locked) {
q4.controls.get(0).setDisabled(true);
}
else {
q4.controls.get(0).setDisabled(false);
}
}