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.
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
'Status_Toggle.Value' did all the magic..!!
Thanks mate..
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 🙂
WarrenBelz
146,645
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,997
Most Valuable Professional