cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SueZeeBee_ganto
Helper I
Helper I

Patch not working for entries from new users or when no records exist

I've reused a PowerApps example of a questionnaire and moderated tsome of the questions. This solution has this formula on the next button of the last question to insert all answers from the user in the Responseds tab on the data Excel. I can see its goal (check if there is already an entry for that user and if so, update existing record otherwise insert the record).
 
If(!IsBlank(LookUp(Responses;Username=User().FullName;Responses));UpdateIf(Responses;Username=User().FullName;{ResponseId:ResponseId; Answer1:Radio1.SelectedText.OptionText;Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");Answer3:Text(Slider1.Value); Answer4:Radio1_1.SelectedText.OptionText;Answer5:Radio5_1.SelectedText.OptionText;Username:User().FullName});
UpdateContext({NewSurvey:Patch(Responses;Defaults(Responses); {ResponseId:Text(CountRows(Responses)+1); Answer1:Radio1.SelectedText.OptionText;Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");Answer3:Text(Slider1.Value); Answer4:Radio1_1.SelectedText.OptionText;Answer5:Radio5_1.SelectedText.OptionText;Username:User().FullName})}));;Navigate(Finish_Screen;ScreenTransition.Fade)
 
I can enter the answers in the quiz without errors. However when the datasheet Responses is empty or it does not have a previous record for that user, it does not insert the anwsers. IF there is already an answer for that user, it updates it.
When I only use this part, it inserts every entry:
 
UpdateContext({NewSurvey:Patch(Responses;Defaults(Responses); {ResponseId:Text(CountRows(Responses)+1); Answer1:Radio1.SelectedText.OptionText;Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");Answer3:Text(Slider1.Value); Answer4:Radio1_1.SelectedText.OptionText;Answer5:Radio5_1.SelectedText.OptionText;Username:User().FullName})});;Navigate(Finish_Screen;ScreenTransition.Fade)
 
Can anyone help me what I need to change to the first formula so it works correctly. Update when records exists, insert when there ar no records or no record for that user.

1 ACCEPTED SOLUTION

Accepted Solutions
yashag2255
Dual Super User II
Dual Super User II

Hi @SueZeeBee_ganto 

 

Can you try to update the formula as:

 

If(
CountRows(Filter(Responses;Username=User().FullName))>0;
UpdateIf(Responses;Username=User().FullName;
{
ResponseId:ResponseId; 
Answer1:Radio1.Selected.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value); 
Answer4:Radio1_1.Selected.OptionText;
Answer5:Radio5_1.Selected.OptionText;
Username:User().FullName});
UpdateContext(
{NewSurvey:
Patch(Responses;Defaults(Responses); {
ResponseId:Text(CountRows(Responses)+1); 
Answer1:Radio1.Selected.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value); 
Answer4:Radio1_1.Selected.OptionText;
Answer5:Radio5_1.Selected.OptionText;
Username:User().FullName})}));;Navigate(Finish_Screen;ScreenTransition.Fade)

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

4 REPLIES 4
v-xida-msft
Community Support
Community Support

Hi @SueZeeBee_ganto ,

I have made a test on my side, please consider modify your formula as below:

 

If(
 !IsBlank(LookUp(Responses; Username = User().FullName)); // Mofify formula here
 UpdateIf(
          Responses;
          Username=User().FullName;
          {
          ResponseId: ResponseId; 
          Answer1:Radio1.SelectedText.OptionText;
          Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
          Answer3:Text(Slider1.Value); 
          Answer4:Radio1_1.SelectedText.OptionText;
          Answer5:Radio5_1.SelectedText.OptionText;
          Username:User().FullName
         }
);
UpdateContext({
                NewSurvey: Patch(
                                   Responses; 
                                   Defaults(Responses); 
                                   {
                                      ResponseId: Text(CountRows(Responses)+1); 
          Answer1:Radio1.SelectedText.OptionText;
                                      Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
                                      Answer3:Text(Slider1.Value); 
                                      Answer4:Radio1_1.SelectedText.OptionText;
                                      Answer5:Radio5_1.SelectedText.OptionText;                
                                      Username:User().FullName
                                   }
                        )
             })
);;
Navigate(Finish_Screen;ScreenTransition.Fade)

 

or

Set(FindingRecord, LookUp(Responses; Username = User().FullName));;
If(
 !IsBlank(FindingRecord); // Mofify formula here
 UpdateIf(
          Responses;
          Username=User().FullName;
          {
          ResponseId: ResponseId; 
          Answer1:Radio1.SelectedText.OptionText;
          Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
          Answer3:Text(Slider1.Value); 
          Answer4:Radio1_1.SelectedText.OptionText;
          Answer5:Radio5_1.SelectedText.OptionText;
          Username:User().FullName
         }
);
UpdateContext({
                NewSurvey: Patch(
                                   Responses; 
                                   Defaults(Responses); 
                                   {
                                      ResponseId: Text(CountRows(Responses)+1); 
          Answer1:Radio1.SelectedText.OptionText;
                                      Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
                                      Answer3:Text(Slider1.Value); 
                                      Answer4:Radio1_1.SelectedText.OptionText;
                                      Answer5:Radio5_1.SelectedText.OptionText;                
                                      Username:User().FullName
                                   }
                        )
             })
);;
Navigate(Finish_Screen;ScreenTransition.Fade)

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for your reaction. I've replaced my formula with both versions of the formulas on a blank Excel datasheet. In both cases this leads to insert with a new record but without data from the questionnaire. Only the powerapps_id column shows data.  

yashag2255
Dual Super User II
Dual Super User II

Hi @SueZeeBee_ganto 

 

Can you try to update the formula as:

 

If(
CountRows(Filter(Responses;Username=User().FullName))>0;
UpdateIf(Responses;Username=User().FullName;
{
ResponseId:ResponseId; 
Answer1:Radio1.Selected.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value); 
Answer4:Radio1_1.Selected.OptionText;
Answer5:Radio5_1.Selected.OptionText;
Username:User().FullName});
UpdateContext(
{NewSurvey:
Patch(Responses;Defaults(Responses); {
ResponseId:Text(CountRows(Responses)+1); 
Answer1:Radio1.Selected.OptionText;
Answer2:Replace(Concat(Listcollect;OptionText & ", ");Len(Concat(Listcollect;OptionText & ", "))-1;1;" ");
Answer3:Text(Slider1.Value); 
Answer4:Radio1_1.Selected.OptionText;
Answer5:Radio5_1.Selected.OptionText;
Username:User().FullName})}));;Navigate(Finish_Screen;ScreenTransition.Fade)

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

That did the trick, thank you!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,429)