web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / OnChange Toggle, updat...
Power Apps
Unanswered

OnChange Toggle, update Collection value with 1 or 0

(0) ShareShare
ReportReport
Posted on 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:
I have the same question (0)
  • Verified answer
    Sundeep_Malik Profile Picture
    6,484 on at

    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 🙂

     

     

  • ozzie14 Profile Picture
    67 on at

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

     

    Thanks mate..

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 759 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 310 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 228

Last 30 days Overall leaderboard