cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Looping through several checkboxes to define one patch instead of a lot.

Hello community,

 

I've created a screen with several checkboxes. Based on the checkboxes value I need to write seperate records in a sql datasource.

 

I have a save button that checks the values and writes them to the database. It works fine, but it's a big list of IF's and I was wondering if there's a way to loop through the checkboxes in a more generic way and collect the values to make a more clean "save" function.

 

Here's the code for one checkbox right now, as you can imagine when I have 9 checkboxes I need to add 9 times this code under 1 button's OnSelect. The code checks if the record already excists, and writes it away when there's no record found.

 

Every checkbox should create it's own record. (It's a selection of machines that is used in a production process, that are stored in a "machinesused" table)

 

 

 

 

 

If(
    checkGerling1.Value = true;
    If(
        LookUp(
            '[dbo].[machinesused]';
            prodid = varProdID && bladenumber = Value(txtBladeNrBrazingHM.Text);
            "found"
        ) = "found";
        Notify("Dubbel");
        Patch(
            '[dbo].[machinesused]';
            Defaults('[dbo].[machinesused]');
            {
                machineid: LookUp(
                    '[dbo].[machines]';
                    machinecode = "G1";
                    machine_id
                );
                bladenumber: Value(txtBladeNrBrazingHM.Text);
                prodid: varProdID
            }
        )
    );
    "false"
)

 

 

 

 

 

Is there a way to do this more clean? Instead of copy pasting x amount of these statements under one Button's OnSelect? Where x = amount of checkboxes.

 

See the attached file for a visual impression of what I'm trying to do.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Frequent Visitor

Re: Looping through several checkboxes to define one patch instead of a lot.

I learned about collections pretty fast after I posted this so I figured just creating a collection and updating it on the OnCheck/OnUncheck. And just use Collect(sqldatasource,checkboxcollcetion) to write it to a sql table 🙂

 

Problem solved!

 

 

View solution in original post

1 REPLY 1
Highlighted
Frequent Visitor

Re: Looping through several checkboxes to define one patch instead of a lot.

I learned about collections pretty fast after I posted this so I figured just creating a collection and updating it on the OnCheck/OnUncheck. And just use Collect(sqldatasource,checkboxcollcetion) to write it to a sql table 🙂

 

Problem solved!

 

 

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (4,892)