I have a powerapp Send Email button which should disable once its clicked once. Next time if user access the app, button should be disabled as its clicked once already.
I wrote below code
Send Email OnSelect
Set(SendEmailClicked,true);
Send Email Display Mode
If(SendEmailClicked,DisplayMode.Disabled,DisplayMode.Edit)
The Send Email button gets disabled once its clicked. However if i refresh the app, button gets again into Edit Mode. May i know how to avoid this?
All variables and collections are cleared when an app is refreshed. If you need data to be stored persistently across different sessions, you'll have to use a permanent data source like SharePoint, SQL, Dataverse, etc. There are several ways to set this up, and I'll provide a simple example using Sharepoint.
1. Begin by creating a SharePoint list named "Email Log." While you only need one column, you can add more if necessary. In this example, we will use the Title field to store the email addresses of the individuals clicking the button.
2. Connect the newly created SharePoint list as a data source, and in the App > OnStart event, add the following formula:
ClearCollect(colSentEmail, Filter('Email Log', Title = User().Email))
3. Then, on your Send Email Button, OnSelect property, add the following code after your send email event:
Patch('Email Log', Defaults('Email Log'), {Title: User().Email});
ClearCollect(colSentEmail, Filter('Email Log', Title = User().Email))
4. Finally, on the DisplayMode property of your send email button add this formula:
If(CountRows(colSentEmail) = 0, DisplayMode.Edit, DisplayMode.Disabled)
When a user clicks the "Send Email" button once, it is logged in the SharePoint list. The app checks this list for the log entry each time the app is launched to determine if the logged-in user has clicked the button before.
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Cheers!
Rick Hurt
WarrenBelz
146,522
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,890
Most Valuable Professional