I have a very large form, and for each question, I used the below design to make the form shorter and look better. So I am capturing the note, image and action on a popup.
The (Add Note, Media and Action) label and icon for all questions have the same OnSelect values. Below is the code for Action OnSelect for label and icon.
If(IsBlank(LookUp(temp_action,action_category = Parent.DataField,action_required)),
Set(add_action_show_fields,1);
Set(weekly_safety_inspection_add_inspection,1);
, Set(view_action_fields,1));Set(temp_category,Parent.DataField);
Now there is a duplication of codes, and if I change anything, I have to replicate the code on all locations manually.
Thanks in advance for any suggestions.
What is it in your Formula that you are repeating and what is the need/use for it? You showed a bunch of variables, but not mentioning what their purpose is.
Hi @RandyHayes ,
Thank you for replying.
I am storing my data in SQL server, and I use a collection to temporary hold data named temp_action". I am checking if the collection contains any value for the DataCard. I used Parent.DataField to get the name of the field in the collection.
If there is no info for that field, I set add_action_show_fields and weekly_safety_inspection_add_inspection to 1 to open a popup and show the blank fields. If there is data, I set view_action_fields to 1 and open another popup to view the information.
Also, I set the temp_category to add the information to the right field in the collection.
If(IsBlank(LookUp(temp_action,action_category = Parent.DataField,action_required)),
Set(add_action_show_fields,1);
Set(weekly_safety_inspection_add_inspection,1);
, Set(view_action_fields,1));Set(temp_category,Parent.DataField);
I hope that makes sense.
So, in general, yes, you want to always avoid repeating Formulas in PowerApps as much as possible. However, there are times when it is necessary. IN such cases, the formulas should be generic. Meaning that if there is a change to something, the formula does not need to be changed.
Overall, I am not clear as to what purpose you are trying to achieve as this appears to be all in an EditForm.
You have shown a formula but have not mentioned where this formula is in your app. So it is a little difficult to suggest some changes that might help you more.
Hi @RandyHayes ,
So I am trying to create a form to conduct weekly inspections for construction sites.
A user can create several notes for each question, take multiple images, and add numerous actions.
Therefore, I have three different tables for Images, notes and actions and I created popups to allow the user to collect multiple images, notes and actions.
All questions have the same OnSelect values for Image (to open image popup), Notes(to open note popup) and action(action popup). I use Parent.DataField name to check if any data exists and save the data into the right field.
Unfortunately, I can not use the Select function because of the Parent.DataField gets the first DataCard name.
@hadimarashy
So first of all...looking at that picture, you should be utilizing a Gallery for all of these as you really have repetition as it is in the questions. I cannot tell for sure from the picture if you are, but you seem to suggest that you have created a form with this in and, since you were concerned over repetition, I am guessing it is not a gallery.
Can you clarify that?
Hi @RandyHayes ,
I used one gallery for the pass and fail questions for each question. However, I had to create a group for "Note, Media and Action". Because the OnSelect of Note and Media and Action are different also, text and colour will change if there are values in the collection.
Please see the below picture.
Thank you for your help.