Skip to main content

Notifications

Community site session details

Community site session details

Session Id : bPZe6FBofy0hetN1w/K6o0
Power Apps - Building Power Apps
Answered

OnChange Toggle, update Collection value with 1 or 0

Like (0) ShareShare
ReportReport
Posted on 25 Sep 2023 03:52:50 by 67

Dear Power Apps Community Members,

 

I'm a bit stuck with one part of my update screen.

 

I have taken all relevant data from a (SQL Server) table, in a collection (one row only). Displayed them in a Canvas App and OnChange of any of the displayed fields, updating the Collection. Finally if the user Clicks the 'Save' button the row will be updated.

 

Every other field is getting updated as expected. However my issue is with a toggle button.

 

The purpose of the button is to reflect the 'status' column in the DB Table which contains 1 or 0 (datatype: tinyint). It denotes whether the record is active or inactive, where 1 = active.

status.PNG

I have defined the Default value of the Toggle with:

 

If(First(CustRec).status = 1, "true", "false")

 

CustRec is the name of Collection. Falsetext = "Inactive", Truetext = "Active"

 

I'm a bit clueless how to update the collection value on the basis of the user clicking on the 'Status' toggle button to change the status of the customer (only when such a change is needed).

The OnChange value is:

 

UpdateIf(CustRec,
 status = ThisRecord.status,
 {status:If(Status_Toggle="true",0,1)
 }
)

 

The idea is: if the value is 'true' or 1 now, Onchange it should be 0 else 1.

 

However this is not working! I have tried a few other options but they doesn't work either!

 

Any suggestion to the right direction will be really appreciated.

 

Thanks.

Ozzie

 

Categories:
  • ozzie14 Profile Picture
    67 on 25 Sep 2023 at 05:49:23
    Re: OnChange Toggle, update Collection value with 1 or 0

    'Status_Toggle.Value' did all the magic..!!

     

    Thanks mate..

  • Verified answer
    Sundeep_Malik Profile Picture
    6,480 on 25 Sep 2023 at 04:50:35
    Re: OnChange Toggle, update Collection value with 1 or 0

    Hey @ozzie14 

     

    You can try the following things. I hope it works. 

     

    1) Set the Default property of the toggle button based on the initial status in your collection:

     

    First(CustRec).status = 1

     

    2) Use the OnChange property of the toggle button to update the status in the collection when the user clicks the button:

     

    UpdateIf(
    CustRec,
    status = ThisRecord.status,
    { status: If(Status_Toggle.Value, 1, 0) }
    )

     

    3) On the save button, use the following similar expression:

     

    Patch(
    YourSQLTable, // Replace with your table name
    LookUp(YourSQLTable, ID = First(CustRec).ID), // Find the record to update
    { status: First(CustRec).status } // Update the status field
    )

     

    Dont exactly follow the expressions, make similar ones. 

     

     

    I hope this helps 🙂

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,645 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,997 Most Valuable Professional

Leaderboard
Loading started
Loading complete