I have a very complex logic statement that uses multiple settings to determine if to perform a Patch() function.
I use Notify() to isolate which statement is firing.
I have isolated it to Statement#4 of my complex logic, AI Suggested to use one patch statement instead of 6 identical patch statements within in the logic construct. The first logic statement below is what that looks like using AI's suggestion for only #4 the other 5 are the way I had #4 originally. AI Also suggested to set up textboxes to display what data is being stored in the variables so I can validate it is correct. In both instances the variables are set correctly, complex Logic, no logic, just set variable and Patch(). I set the variables for the Patch() and then set the variable to patch to true. Here is the relevant code for just statement#4, datatypes are correct:
Set(varSel_Scale, Value(studentScore_DD_ExC.Text));
Set(varEdit_Update_Title,ExerciseDay_edit_ExC.Text);
Set(varEdit_Update_Score, Value(studentScore_DD_ExC.Text));
Set(varEdit_Updated_Observed, txt_Observation_edit_ExC.Text);
//Number #4
Set(var_Perform_Patch, true);
Notify("SUCCESS 4- You have a high enough ratio of Observed versus Graded Tasks and You provided a required observation.",NotificationType.Success)
Here is the Actual Patch Logic statement:
If(var_Perform_Patch,
//True Part
Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: varEdit_Update_Title, Score:varSel_Scale, Observation:varEdit_Updated_Observed } );
Notify("Patch should have fired",NotificationType.Information),
//False Part
"";
Notify("Patch should have NOT fired",NotificationType.Information)
);
I also set up a separate Test Button that has the exact same set statements as the one in the logic construct, here is the code for that:
Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: varEdit_Update_Title, Score:varSel_Scale, Observation:varEdit_Updated_Observed } )
As you can see the patch statements are identical. So this is my problem: When I click on the button with the complex logic all the variables are set correctly as seen in the AI suggested textboxes. But the data is not pushed to my SP List at all, it says it does. When I click on the button that just has the Set(variables) & Patch() functions it updates the variables and SP List correctly.
So here is the question: Why does the same Patch(statement) in a complex logic construct not update correctly, especially when all the values are the same as the Patch(statement) that is isolated in a simpler formula and does update correctly?
I am at my wits end.
Some of you might say "I need your entire logic statement" you don't because the rest is not relevant. You just need to know #4 is currently firing given the inputs. However, if you want here is my entire logic statement:
//Variable Resets
ClearCollect(colFilteredByStudent, Filter([@Ex_Observations], Part_ID = Gallery1_1.Selected.ID));
ClearCollect(colFilteredByTask, Filter(colFilteredByStudent, Task_ID = selectedRecordID));
Set(varSel_Scale, Value(studentScore_DD_ExC.Text));
Set(varEdit_Update_Title,ExerciseDay_edit_ExC.Text);
Set(varEdit_Update_Score, Value(studentScore_DD_ExC.Text));
Set(varEdit_Updated_Observed, txt_Observation_edit_ExC.Text);
Set(var_Perform_Patch, false);
Set(var_CountRecs, ClearCollect(col_Student_Grades, Filter([@Ex_Observations], Part_ID=Value(Gallery1_1.Selected.ID))));
Set(var_Stu_Grade_Count, CountRows(var_CountRecs));
Set(var_StuID_Selected, Gallery1_1.Selected.ID);
Set(Var_Ratio_Obser_DividedBy_Tasks,(CountRows(Filter(colFilteredByStudent,!IsBlank(Observation))))/(CountRows(var_CountRecs)+1));
Set(var_If_Test_P1, If((var_Stu_Grade_Count <=2 && !IsBlank(txt_Observation_edit_ExC.Text)), true, If(Value(varSel_Scale) > 2, true, If(IsBlank(txt_Observation_edit_ExC.Text),false,true))));
Set(var_If_Test_P1_A, If(var_Stu_Grade_Count <=2,true,false));
Set(var_If_Test_P1_B, IsBlank(txt_Observation_edit_ExC.Text));
Set(var_IF_Test_P1_C,Value(varSel_Scale)<3);
Set(var_If_Test_P1_AB,If(var_If_Test_P1_A, true ,If(Value(varSel_Scale)>2, true ,If(IsBlank(txt_Observation_edit_ExC.Text), false , true ))));
Set(var_If_Test_P2,(Var_Ratio_Obser_DividedBy_Tasks>.2499));Set(var_Notify_msg_P1_A,If(var_If_Test_P1_AB,"Success","You did not include a Required Observation for the score you have selected."));
Set(var_If_Test_P2_A,Var_Ratio_Obser_DividedBy_Tasks>.2499);
If(var_If_Test_P1_A,
// Level 1 IF() True Part = Less than or equal to 2 graded tasks so far
If(var_IF_Test_P1_C, // Scored less than 2 = True
//2nd Level If() True Part, 1st Level If() True part = Task Observation is Blank "Do NOT Submit the form"
If(var_If_Test_P1_B, // Observation is blank
Notify("ERROR:1"&"You did not include an Observation for the level of score you are setting.",NotificationType.Error),
//ADD all Record processing events after this entry AND before notify:
Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: ExerciseDay_edit_ExC.Text, Score:Value(studentScore_DD_ExC.Text), Observation:txt_Observation_edit_ExC.Text } );
Refresh(Ex_Observations);
Notify("SUCESS:1"&"Sucess, You provided an observation for the level of score you are setting.", NotificationType.Success)
) ,
//2nd Level If() False Part, 1st Level If() True part "Submit the Form Graded Task scored below 2, with an Observation"
//ADD all Record processing events after this enty AND before notify:
If(var_If_Test_P1_B, // if true observation is blank
If(var_IF_Test_P1_C, // iF sCALE LESS THAN 3
Notify("ERROR:2"&"You did not include an Observation for the level of score you are setting.",NotificationType.Error)
,
Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: ExerciseDay_edit_ExC.Text, Score:Value(studentScore_DD_ExC.Text), Observation:txt_Observation_edit_ExC.Text } );
Refresh(Ex_Observations);
Notify("Good 2"&"Success, You provided an observation for the level of score you are setting.", NotificationType.Success)
)
,
Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: ExerciseDay_edit_ExC.Text, Score:Value(studentScore_DD_ExC.Text), Observation:txt_Observation_edit_ExC.Text } );
Refresh(Ex_Observations);
Notify("Good 3"&"Success, You provided an observation for the level of score you are setting.", NotificationType.Success) //Observation True
)
)
,
// First Level If() False Part = More than 2 Tasks graded, then check Task Scale for an Observation, and then if the all observations/grades tasks = 25% of higher
If(var_If_Test_P2_A, //Ratio >.25
// Second Level If() True Part inside First Level If() False part = Observed versus Graded Task ratio is greater than 25% and there are more than 2 graded Tasks
If(var_IF_Test_P1_C, //---Scale Less than 3
If(var_If_Test_P1_B, // Observation Empty
Notify("STOPPED 4- You did not provide an observation for level of score you selected.",NotificationType.Error)
, //###Observation Provided
Set(var_Perform_Patch, true);// Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: varEdit_Update_Title, Score:varSel_Scale, Observation:varEdit_Updated_Observed } )
//Refresh(Ex_Observations);
// NewForm(EditGrade_frm);
Notify("SUCCESS 4- You have a high enough ratio of Observed versus Graded Tasks and You provided a required observation.",NotificationType.Success)
)
,
If(var_If_Test_P1_B, // Scale Greater than 2 & Observation Empty
Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: ExerciseDay_edit_ExC.Text, Score:Value(studentScore_DD_ExC.Text), Observation:txt_Observation_edit_ExC.Text } );
Refresh(Ex_Observations);
Notify("Success 5 - You do not need to provide an observation and the ratio is high enough.",NotificationType.Success)
, //###Observation Provided
// Scale Greater than 2 Observation Provided
Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: ExerciseDay_edit_ExC.Text, Score:Value(studentScore_DD_ExC.Text), Observation:txt_Observation_edit_ExC.Text } );
Refresh(Ex_Observations);
Notify("SUCCESS 5 - You have a high enough ratio of Observed versus Graded Tasks and You provided a required observation",NotificationType.Success)
)
)
,
// Second Level If() False Part inside First Level If() False part = Observed versus Graded Task ratio is lESS than 25% and there are more than 2 graded Tasks
If(var_If_Test_P1_B, // Observation Empty
Notify("STOPPED 6 -You did not provide an observation for the rating you selected which you need to keep the ratio above 25%.",NotificationType.Error)
, //###Observation Provided
Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: ExerciseDay_edit_ExC.Text, Score:Value(studentScore_DD_ExC.Text), Observation:txt_Observation_edit_ExC.Text } );
Refresh(Ex_Observations);
Notify("SUCCESS 6 -You have a high enough ratio of Observed versus Graded Tasks and You provided a required observation",NotificationType.Success)
)
)
);
If(var_Perform_Patch,
//True Part
Patch( Ex_Observations, LookUp(Ex_Observations, ID = Gallery4_ExC.Selected.ID), { Title: varEdit_Update_Title, Score:varSel_Scale, Observation:varEdit_Updated_Observed } );
Notify("Patch should have fired",NotificationType.Information),
//False Part
"";
Notify("Patch should have NOT fired",NotificationType.Information)
);
Refresh(Ex_Observations);
This is solved now. It was a process.
1 Created variables for every piece of the Patch(). That did not work.
2 What' going on with the variables?
3 Created Text boxes for the variables and then created a gallery to see the record target for the patch(). Everything Displayed correctly. That did not work. How could variables, ALL correct not allow the patch()?
4 Asked for help in a DOD chat for coders.
5 Someone provided a solution that used the control.text properties set in #2 above.
That worked. Crazy! They said it has something to do with Power Apps being Async. and maybe the variables not being fully baked. Even though you can see the correct values in the controls in the boxes before you even pressed the buttons. I used other controls to set the variables and populate the boxes. Because I thought it was an Order of Operations issue. So that should have made the variables resolve and display their values. So when I pushed the Submit button to get results using just variable set beforehand, somehow did not work; only picking up the Control.Text values worked.
I guess if your patch() is acting up maybe try setting variables, create text boxes to hold the variables, the use the control.Text property to pull the Text properties directly in the Patch(). That is the only difference between the code I submitted in OP and the solution.