cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Pieter_NL
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
Pieter_NL
Frequent Visitor

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
Pieter_NL
Frequent Visitor

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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

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