cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ersula82
Level: Powered On

ForAll Toggle Values

I have an app that I've created for parents to checkin their tardy students:

  • I have a gallery with toggles inside of the gallery. The gallery displays student names with a toggle next to it
  • I have a submit-button outside of the gallery. The submit button patches the names of any students that have a toggle that is "true" back to a sharepoint list.

I currently have a formula in the onselect of the Submit_Button that goes as follows:

ForAll(Gallery1.AllItems,

If(Toggle1.Value= true,
If(Reasons_DD.Selected.Value="Other",
Patch(Visitors,Defaults(Visitors),{Title:Title,Checkin_x0020_DateTime:Now(),ReasonsSmiley Surprisedther_Txtbox.Text}),
Patch(Visitors,Defaults(Visitors),{Title:Title,Checkin_x0020_DateTime:Now(),Reasons:Reasons_DD.Selected.Value}))))

 

The above formula works correctly. It will patch any true toggles back to sharepoint. So, this is great but....

 

I want the Submit_Button to behave like the following:

  • When the parent clicks the Submit_Button, if all toggles are true, patch all of those records to sharepoint
  • When the parent clicks the Submit_Button, if some toggles are false, display a popup message (I've already created the popup message). 
  • I've disabled the button if all toggles are false so that part is already complete

Since Susie, Johnny and Billy's toggles are false, I want the popup to display so it can alert the parent that you have some children you haven't toggled.

Please see screen shot

captures1.png

 

 

 

 

6 REPLIES 6
SteveMC
Level: Powered On

Re: ForAll Toggle Values

You can try something like this:

ForAll(
    Gallery1.AllItems,
    Collect(
        toggleValues,
        Toggle1.Value
    )
);
If(
    false in toggleValues.Value,
    UpdateContext({showPopup : true}),
    ..Do your Patching...
)

..in your pop up's Visible property: showPopup

 

Hope this helps

KroonOfficeSol
Level 10

Re: ForAll Toggle Values

@ersula82

 

Better you could ClearCollect() your datasource and connect your gallery to this collection. Then patch() to the collection when the toggle is changed.

 

Then with the collections do your logic. Like:

If(CountRows(YourCollection) = CountIf(YourCollection, CheckIn = true), Patch(toSharePoint), UpdateContext({M_Show:1}))

On your message you put this:

M_Show = 1

Then on the cancel button you reset the M_Show to 0.

 

Add the rest off you logic where needed. 

 

Hope this helps.

 

Paul

ersula82
Level: Powered On

Re: ForAll Toggle Values

@SteveMC,

 

So, I tried the collection function and it was successful but here is what works and what doesn't. Screen shots are below:

 

What works:

  • The collection reads all of the toggle values and locates the false values successfully
  • When the submit button is pressed and it finds some of the toggle values are false in the collection, the popup group displays successfully
  • I've added a "Yes" button and a "Cancel" button to the popup group. The "Yes" button successfully patches only the "true" toggle values inside of the gallery back to sharepoint, clears the collection and navigates back to the welcome screen.  The "Cancel" button clears the collection and returns to the gallery. This is all correct
  • Upon the onselect of the Submit_Button and when all toggle values are true, the popup group does not display. This is correct

What does not work:

  • Upon the onselect of the Submit_Button and when all toggle values are true, the patch should patch all records' Title column, current date/time and the reason value selected in the dropdown box or text in the textbox if visible. It does not. I have an If statement for the patch due to the dropdown box (Reasons_DD). I need the patch to either patch the dropdown selected value OR if the dropdown selected value is "other", I need it to patch the text that the user types in the textbox (Other_txtbox) that becomes visible when "other" is selected as a reason for being tardy
  • I cannot add a navigate function to the below formula because if any toggle values are false, the popup displays then flashes for a second and then proceed with the navigation function going back to the welcome screen. How do I navigate my users back to the welcome screen after patching is done?

 

Formula for the onselect of the Submit_Button (Outside of the gallery). Green font is what works, red font is what doesn't work:

 

ForAll(Gallery1.AllItems,Collect(toggleValues,{Toggles:Toggle1.Value}));If( false  in toggleValues,UpdateContext({VarOpenPopup: true }),If(Reasons_DD.Selected.Value="Other",Patch(Visitors,Defaults(Visitors),{Title:Title,Checkin_x0020_DateTime:Now(),ReasonsSmiley Surprisedther_Txtbox.Text}),Patch(Visitors,Defaults(Visitors),{Title:Title,Checkin_x0020_DateTime:Now(),Reasons:Reasons_DD.Selected.Value});Clear(toggleValues)))
 
You can see behind this popup overlay that some toggle values are false, so, the popup displays successfully. The onselect of the "Yes" button patches the "true" toggle records, clears the collection and navigates back to welcome screen. Yay!
Here is the formula in the onselect of the "Yes" button:
 
ForAll(Gallery1.AllItems,
If(Toggle1.Value= true,
If(Reasons_DD.Selected.Value="Other",
Patch(Visitors,Defaults(Visitors),{Title:Title,Checkin_x0020_DateTime:Now(),ReasonsSmiley Surprisedther_Txtbox.Text}),
Patch(Visitors,Defaults(Visitors),{Title:Title,Checkin_x0020_DateTime:Now(),Reasons:Reasons_DD.Selected.Value}))));
Navigate(WelcomeScreen,ScreenTransition.Fade,{fromWelcomeScreen: true });Reset(CurbsmartNo_Txtbox);Reset(Reasons_DD);Reset(Other_Txtbox);Refresh(Visitors);UpdateContext({VarOpenPopup:false});Clear(toggleValues)
 
Capture_popup.PNG


In the below screen shot, if all toggle values are true and upon onselect of the Submit_Button, nothing happens. The patch does not work. Also, where do I implement navigation after these 4 true records are patched?

Capture4.PNG

 

 

 Thank you so much for your help! This is the last step before my app is completed so I'm really appreciative. I've tried to be as detailed as possible to help you help me Smiley Happy

 

Ersula

 

 

ersula82
Level: Powered On

Re: ForAll Toggle Values

@KroonOfficeSol

 

Paul I ended up responding below in the thread and detailing what didn't work. I'm almost there...

Community Support Team
Community Support Team

Re: ForAll Toggle Values

Hi @ersula82,

For your first question, could you please share a bit more about the Title value you set for the Title column within your Patch function?

I have made a test on my side, and don't have the issue that you mentioned. The screenshot as below:8.JPG

Set the OnSelect property of the "Submit" button to following formula:

Clear(toggleValues);
ForAll(Gallery1.AllItems,Collect(toggleValues,Toggle1.Value));
If(
    false in toggleValues,
    UpdateContext({VarOpenPopup:true}),
    If(
        Reasons_DD.Selected.Value="Other",
        ForAll(Gallery1.AllItems,Patch('20181025_case8_Visitors',Defaults('20181025_case8_Visitors'),{Title: Label3.Text,Checkin_x0020_DateTime:Now(),ReasonsSmiley Surprisedther_Txtbox.Text})),
        ForAll(Gallery1.AllItems,Patch('20181025_case8_Visitors',Defaults('20181025_case8_Visitors'),{Title: Label3.Text,Checkin_x0020_DateTime:Now(),Reasons:Reasons_DD.Selected.Value}))
    )
)

On your side, you should type the following:

Clear(toggleValues);
ForAll(Gallery1.AllItems,Collect(toggleValues,Toggle1.Value));
If(
    false in toggleValues,
    UpdateContext({VarOpenPopup:true}),
    If(
        Reasons_DD.Selected.Value="Other",
        ForAll(Gallery1.AllItems,Patch(Visitors,Defaults(Visitors),{Title: Label3.Text,Checkin_x0020_DateTime:Now(),ReasonsSmiley Surprisedther_Txtbox.Text})),
        ForAll(Gallery1.AllItems,Patch(Visitors,Defaults(Visitors),{Title: Label3.Text,Checkin_x0020_DateTime:Now(),Reasons:Reasons_DD.Selected.Value}))
    )
)

The GIF screenshot as below:

Test1.gif

Please also take a try to modify your formula as below:

ForAll(Gallery1.AllItems,Collect(toggleValues,{Toggles:Toggle1.Value}));
If(
false in toggleValues,
UpdateContext({VarOpenPopup: true }),
If(
Reasons_DD.Selected.Value="Other",
Patch(Visitors,Defaults(Visitors),{Title:Title,Checkin_x0020_DateTime:Now(),ReasonsSmiley Surprisedther_Txtbox.Text}),
Patch(Visitors,Defaults(Visitors),{Title:Title,Checkin_x0020_DateTime:Now(),Reasons:Reasons_DD.Selected.Value})
)
);
Clear(toggleValues) /* <-- Put the Clear function outside the If function */

 then check if the issue is solved.

 

For your second question, please take a try with the solution I provided above, then check if the issue is solved.

If the issue still exists, please take a try to re-create your app, then check if the issue still exists.

 

Best regards,

Kris

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.
KroonOfficeSol
Level 10

Re: ForAll Toggle Values

@ersula82

 

In your first patch you miss a : after reasons. Or is this just the Forum replace it by a label?

 

Still you are looking at it from a wrong perspective. When you go to this screen you know what your filters are on your dataset, because you use this in the .items off your gallery. You should store this filtered dataset in a collection at goïng to the screen. So on the button.OnSelect which brings you there or the Screen.OnVisible you do like:

 

ClearCollect(MyCollection, Filter(MyDataSource, conditions), {Title:VisitorFullName, Present: false, NotPresent:false, Reason:'', ToggleValue:false})

 

 

By the way, I remodeled your SP List and add a Presenting and NotPresenting boolean columns. These will let you see who where there and make it possible that you can register NotPresenting beforehand (Visitor calls he will be not there in front with a reason).

 

Then connect your gallery to the collection, do on YourGallery.Items

 

SortByColumns(MyCollection, "StudentName", Ascending)

 

Then every time you change the toggle you do a patch. Probably easiest on MyToggle.Change, just do:

 

Patch(MyCollection, LookUp(MyCollection, StudentID = ThisItem.StudentID), {ToggleValue:MyToggle.Value})

Then your collection is reflexting the changes you make, the rest off you logic is on this collection.

 

 

First on your button do the calculation condition I gave earlier. So the Button.OnSelect is like:

 

If(CountRows(MyCollection) = CountIF(MyCollection, ToggleValue = true), 
	Select(MyPatchButton),
	UpdateContext({ShowMyMessage:1})
)

Yes, you take out the patch out off this formula.

 

 

All the controls off the Message you put in a enhanced group, call this something like MessageGroup. See a video on how to use and enable this here: Learn PowerApps | 17 | Mobile App Template - Part 4 - UserForms

 

Then on the MessageGroup.Visible you do

 

ShowMyMessage = 1

 

 

On the MessageCancel.OnSelect you do:

 

UpdateContext({ShowMyMessage:0}

 

On the MessageSubmit.OnSelect you do:

 

Select(MyPatchButton);
Select(MessageCancel)

On MyPatchButton.OnSelect you put your patch. 

 

ForAll(MyCollection,
Patch(Visitors,Defaults(Visitors), {Title:Title,Checkin_x0020_DateTime:Now(), Presenting: Present, NotPresenting: NotPresent, Reasons:Reason)})
)

Both off theseyou should replace by the column in your collection. 

Smiley Surprisedther_Txtbox.Text
Reasons_DD.Selected.Value

 So patch the values off the text/combobox to you collection on change. For the TextInput.Delay... set this to true.

 

Also:

  • when you want to reset the gallery you should basically reset the collection. Use the ForAll() formula to do this.
  • connect the combobox.DefaultSelectedItems and Textinput.Default to your collection, it will then adjust when you run the first line.

So basically I build your solution now ;-)  Hope this helps.

 

Paul