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

Set value of checkbox in a Gallery Item with ForAll

Hi All,

 

I have been battling with this problem for a day with no success so far.  I'll put my problem into context:

 

- I have created two entities in the CDS named "Task" and "Task template". Their relation is Many to Many, so different tasks can belong to the same template, and different templates can reference the same task. 

- I have created a combox box that displays the name of the template, and I have created a Gallery listing the Tasks.. I have inserted a checkbox to the gallery.

 

My goal is that when clicking a button called "Add template", the checkbox of the corresponding task is set to true (later on I want to use this checkbox to know what tasks I have to include in another table entity).

 

So, the code of the "Add template" button is the following: 

 

ForAll(
   Gallery1.AllItems;
   If(
       TemplateCombo.SelectedText.Value in Gallery1.Selected.'Task template'.'Task template name';
       Gallery1.Selected.Checkbox3.Value = true;
       Gallery1.Selected.Checkbox3.Value = false
      )
   )

 

But nothing happens. I'm thinking maybe the Gallery1.Selected can not be used. Any ideas?

 

Thanks in advanced.

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft v-siky-msft
Microsoft

Re: Set value of checkbox in a Gallery Item with ForAll

@kostaskoufos 

Do you mean you want to use the button to control the checkboxes?

You can set button OnSelect: 

Set(MyVar,TemplateCombo.Selected.Value )

Modify the Checkbox Default:

!IsEmpty(Filter(ThisItem.'Task template'.'Task template name', 'Task template name' in MyVar))

If the checkboxes still uncheck, please ensure the selected Template has bound to the Task.

I have test and it works well.  If it still doesn't work for you. Feel free to post back.

StoG_20.gif

 Sik

View solution in original post

10 REPLIES 10
dynamicsedge
Level 8

Re: Set value of checkbox in a Gallery Item with ForAll

@kostaskoufos 

 

 Gallery1.Selected.Checkbox3.Value = true

 

What you said above means something else.

 

"=" is not to set a control nor value. = is a comparison somewhat like == in some programming languages.

Here you are simply comparing something to true, not setting the control value.

 

You have to think inverse in PowerApps.

 

Go to Checkbox Default Property and put the if condition there returning a boolean e.g.

 

If(Condition, true, false)

 

If you put the checkbox in Gallery,  you can use ThisItem, etc. instead of ForAll. If you did not put checkbox in the gallery, try putting it in there to take advantage of using ThisItem to take action on the corresponding task from Gallery and automatically put checkbox on each record.

kostaskoufos
Level: Powered On

Re: Set value of checkbox in a Gallery Item with ForAll

Hi dynamicsedge, 

 

First of all, thank you so much for your response. I understand what you say and I realize I hadn't grasp the concept of the powerapps. 

 

I have tested your proposal and that certainly works! However, it doesn't suit my app completely. That is because most probably users will need to add several templates, and with this solution when I change the value of the combo the corresponding checkboxes get unchecked. 

 

I will keep working with what you said in mind and hopefully I'll post a solution.

 

Thank yoU!

kostaskoufos
Level: Powered On

Re: Set value of checkbox in a Gallery Item with ForAll

I thought of working in a workaround, but came out unsucessful. 

 

I added a new field to the CDS entity called "Selected". When pressing the "Add template" I would Patch the records so that this Selected field is true. The checkbox Default property depends upon this Selected field. 

 

However, it seems I can not filter upon the relationship.

 

Patch('Tasks';Filter(Tasks'; XXXX);{Selected : true})

 

In XXX, where the list of fields of the entity Tasks is display, the relation that I created doesn't appear.

 

I'll keep on looking.

dynamicsedge
Level 8

Re: Set value of checkbox in a Gallery Item with ForAll

@kostaskoufos 

 

Try putting not only the Checkbox in the Gallery, but also try putting the Add Template button itself in the Gallery too and applying same principle to the button, and see if this works as well.

Microsoft v-siky-msft
Microsoft

Re: Set value of checkbox in a Gallery Item with ForAll

@kostaskoufos 

If my understanding is correct, here is a simple workaround.

Set Defaults property of check box in gallery:

TemplateCombo.Selected.Value in ThisItem.'Task template'.'Task template name'

Then the items bound to the selected template will all be checked.

Snipaste_2020-01-16_17-37-50.png

Sik

 

kostaskoufos
Level: Powered On

Re: Set value of checkbox in a Gallery Item with ForAll

Hi and thank for your response.

 

That certainly works, but I need to be able to select multiple templates, so when I change the combo the checkboxes get unchecked!

 

 

Microsoft v-siky-msft
Microsoft

Re: Set value of checkbox in a Gallery Item with ForAll

@kostaskoufos 

 

If then, you can try this:

!IsEmpty(Filter(ThisItem.'Task template'.'Task template name', 'Task template name' in TemplateCombo.Selected.Value))

Snipaste_2020-01-17_09-46-17.png

 

Sik

kostaskoufos
Level: Powered On

Re: Set value of checkbox in a Gallery Item with ForAll

Thank you so much for your response.

 

Unfortunately, I have the same problem. When I change the combo, the checkboxes get unchecked.

 

This is the setup that I have:

 

templates.png

 

My idea is to select a value in the combo, click on "Add templates" and then see how the checkboxes get checked for good. Then I could select another value in the combo and repeat the process, maintaining the previously added tasks.

 

Thank you again for your help. I'll keep working on this.

Microsoft v-siky-msft
Microsoft

Re: Set value of checkbox in a Gallery Item with ForAll

@kostaskoufos 

Do you mean you want to use the button to control the checkboxes?

You can set button OnSelect: 

Set(MyVar,TemplateCombo.Selected.Value )

Modify the Checkbox Default:

!IsEmpty(Filter(ThisItem.'Task template'.'Task template name', 'Task template name' in MyVar))

If the checkboxes still uncheck, please ensure the selected Template has bound to the Task.

I have test and it works well.  If it still doesn't work for you. Feel free to post back.

StoG_20.gif

 Sik

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,940)