cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jdhough55
Helper II
Helper II

Checkboxes with the 'WITH' function

Hi All, 

I have a series of checkboxes and one at the top which does Select All. 

The OnCheck on that sets a context var : UpdateContext({AllChecked: true})

The OnUnCheck set the context var : UpdateContext({AllChecked: false})

 

If the user saves the screen (with the checkboxes on) and then goes back into the screen. I want to use the First Record.Column name and if it is Yes.No = Yes then show the tickbox and if it is Yes.No = No then dont show the tickbox. I want the UpdateContexts to overwrite the value (if it is either true or false).

 

I am using an WITH statement on the 'default of each tickbox' 

 

With(
       First(InspectionItemTPHCollection),
       If(
            'PHV Licence' = 'Yes or No'.Yes,
            true,
            AllChecked = true,
            true,
             AllChecked = false,
             false
             
          )
)

This is used so that if it is yes (from the record), show as true, and allchecked as true or false accordingly.

 

It kind of works, but if we do a selectall (uncheck - it doesnt clear all the checkboxes and it brings back what is saved). 

Any idea on how i can craft this WITH command - that is correct ? I am almost there! 

Any help would be amazing. 

 

 

 

13 REPLIES 13
WarrenBelz
Super User
Super User

Hi @jdhough55 ,

Firstly, With() is setting a (very) temporary variable that you have to name and use in the code. I have a blog on its use in the Delegation context. I do not know the context of what you are doing here, but the syntax structure would be something like this

With(
   {wRecord: First(InspectionItemTPHCollection)},
    wRecord.'PHV Licence' = 'Yes or No'.Yes  ||  wRecord.AllChecked
)

You do not need the If/Yes/No (see this blog of mine)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

So I am getting the same issue really... 

When i save individual rows - works fine 

When i select all - it ticks all the boxes

When i de-select all - it keeps the boxes that are saved! 

We are almost there ! 

Any other help would be amazing! 

jdhough55
Helper II
Helper II

So, can i give you some more context please - becasue we almost there on this and it would be amazing for your help. 

 

I need to do a 'save' and i have this by a patch to the collection. I also have a back button which doesnt save - this works great. 

 

I have a checkbox with OnChecked - context variable : true and OnUnchcked same variable but false. If I need to tweak this then thats fine. 

 

Your code almost 99% does the job, but when i de-select it doesnt 'de-select' it just shows what was saved already. 

 

Can you please help a little further please ? I am at a loos end with it and sleepless nights! 

 

@jdhough55 ,

The code I sent will look at the first record in your collection and if the 'PHV Licence' field is Yes and the AllChecked field is true, it returns true, but now I see that the AllChecked is a Variable, so, you really do not need the With() statement here

First(InspectionItemTPHCollection).'PHV Licence' = 'Yes or No'.Yes  ||  AllChecked

I will be offline now due to time zone

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Ahh still the same thing - it isnt removing the unOnCheck. 

 

jdhough55_0-1656330730946.png

 

Also by default all the checkboxes are true, which they shouldnt be.. Esepcially if it is a new investigation then they should default to false. 

@jdhough55 ,

You need to reset them - you can make the Reset property a Variable that you set to false, then true.

jdhough55
Helper II
Helper II

I have done that but they dont refresh becasue of the formula thats on the checkbox which is : 

 

First(InspectionItemTPHCollection).'PHV Licence' = 'Yes or No'.Yes || AllChecked

 

I think this formula needs to change and i really need some help 😞 

jdhough55
Helper II
Helper II

So the AllChecked part is either true or false. So if it is true then we need to show the tick, if it is false then it should be false. So if the record is Yes  and allchecked is false it should be false. 

If Alleched is true and the record is yes then it should show the tick. This gives a bit more context into this annoying problem. Thankyou very much, 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (6,063)