cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kziegler
Frequent Visitor

After a button is pressed I want it to change colors for a certain period of time then back to its original color.

I'm not sure which category this fits under but I would like a few things to happen when you press a button on power apps. I have a list of buttons that I'm not sure should be free-floating or in a gallery and the main goal is to make it easier to log routine repairs to machines.

1. When the button is pressed I'd like it to move to the bottom on the button list.

2. When the button is pressed I'd like it to change color for 5 days, (until the following Monday would be better but I'm not sure how to routinely calculate that date) then change back to it's original color when that time is up or on midnight the following Monday. 

3. When the button is pressed I would like it to create a predetermined item in Sharepoint. There is already a different Power Automate flow set up for each button I want to connect. I just need to modify it from being "on button press" to when a button in Power Apps is pressed.

 

I have no idea how to properly code any of this is my issue. I really want to be able to achieve all of this with MS Flow buttons but those are too limited.

If anyone has any tips or ideas on achieving these goals it would be massively appreciated!!

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

It's easy enough to add a filter into the Sort statement to add the Machine Name (or ID or whatever).

 

Previously, the code I gave you (for the text label, showing the most recent date) was: 

First(Sort(Powerapp_Test, Date_Button_Pushed, Descending)).Date_Button_Pushed

 and the If Statement for the "Fill" Property on the button was

If(First(Sort(Powerapp_Test, Date_Button_Pushed, Descending)).Date_Button_Pushed > DateAdd(Today(), -5, Days), RGBA(255,0,0,1), RGBA(0,255,0,1))

 

I added a "Machine Name" column to the SharePoint list, and I re-arranged the PowerApp a little bit

abrae005_0-1657911847646.png

abrae005_1-1657911958739.png

 

The new code to only return the last clean date for the Batmobile is below. You can see we just added 1 more clause for Filter, based on Machine_Name = Batmobile (with appropriate quotes, of course)

First(Sort(Filter(Powerapp_Test, Machine_Name="Batmobile"), Date_Button_Pushed, Descending)).Date_Button_Pushed

 

And the code for the "Fill" property of the button would become this ... The button would appear green if the device needs to be cleaned, and red if it's been cleaned in the past 5 days and doesn't need to be cleaned again. You can change the colors to suit your needs.

If(First(Sort(Filter(Powerapp_Test, Machine_Name="Batmobile"), Date_Button_Pushed, Descending)).Date_Button_Pushed >= DateAdd(Today(), -5, Days), RGBA(255,0,0,1), RGBA(0,255,0,1))

 

(when I took the screenshot of the buttons, I changed the color value for the green, because (0,255,0,1) is really obnoxious neon green ... The one I used is (0,85,0,1))

View solution in original post

14 REPLIES 14
abrae005
Kudo Collector
Kudo Collector

1. I haven't done this, but you could set ButtonName.X and ButtonName.Y properties (X is left/right and Y is up/down) as part of your OnSelect for the button
2. You'll probably want to add a field in your SharePoint list (or whatever your datasource is) for "ButtonName Last Pressed Date", and set that value to Now or Today as part of the OnSelect. Then, you'll want to use a formula in the button's color property to check if that value is within 5 days of the current day and set the color appropriately
3. You can trigger a Flow with a PowerApps button, but you can also add the item to SharePoint directly from PowerApps without needing the flow.

1 and 2 are both actually super helpful, I'll need to figure out how to code them still. I won't be able to add a date sponge in the list directly as this button would only make an item which is where the flow comes into play, I don't think you can have premade forms in Sharepoint through Power Apps and each button creates a different form and we need to trigger the creation of each form on a weekly basis so Power Automate Flows keep it a little more organized for me.

kziegler
Frequent Visitor

My work flow needs to look a little something like this, please excuse the poor quality, I made it super quick in paint.

 

kziegler_0-1656709820070.png

 

So, if you're using a SharePoint list (Is that what you mean by "Pre-Filled Item in SharePoint" on the beige side of your flow?), you've already got a date for the button press, which can be referenced in Powerapps to help determine the color of the button.

For the Moving Button, you'll want to set the Y property of the button to be a variable, called var_ButtonY Then in the OnSelect property, you can reset the variable, using 

Set(var_ButtonY, 350)

(350 is just an example. Adjust to be higher or lower, depending on where exactly you want the button to move to on the screen). In the screenshot below, you'll notice the "Return Button 1" button, which will set the variable back to 128, which is the original location.

abrae005_0-1657026577288.png

 

For #2, it sounds like (see question above) you're already storing the button push date in your SharePoint, so you'll want to connect that Sharepoint to your powerapp as a data source. Then for the button's "Fill" property, you'll want to create an If/Then statement, checking to see if the date stored is within your range. The code below will need to be updated with the data source details. If the value stored is more than 5 days ago, it will turn the button (a very bright annoying shade of) green, otherwise it will turn red. (Feel free to adjust the RGB values for colors)

If(DataSource.StoredDate < DateAdd(Today(), -5,Days), RGBA(255,0,0,1), RGBA(0,255,0,1))

 

I don't already have a date stored in sharepoint for the button press, if I'm picking up what you're putting down correctly. Theoretically I would be taking the date when the button is pressed and using it to autofill the Sharepoint item, I will be doing the same for the user that presses the button; it will be taking the user's name and putting it in the Sharepoint item when they press the button. 

For the moving button I'm not sure what the substitute for the stored date would be since it's dynamic, not local to sharepoint and changes every time the button is pressed, thought I understand the thought process of it. 

Also with the movement of the button, it's more like the buttons would need to be in a gallery because my thinking was that I'd be able to move the button down to the bottom of the list and as every button is pressed they all move to the bottom after time so after time the button that was first would return to its original position. However the button movement is not super important compared to everything else.  

Also I really appreciate you working with me on this, I've been troubleshooting different ways to make this system easier for my team and Power Apps seemed best, but I know nothing about it or Power FX.

kziegler
Frequent Visitor

I'm not sure if this works but I have a different flow for each button, so I would need to assign each button to start a flow and I'm not sure how to do that

abrae005
Kudo Collector
Kudo Collector

When you say "Sharepoint Item", do you mean adding (or updating) an item in a SharePoint List? Or are we talking about some other type of item?

 

There are lots of articles and tutorials on how to add/update items to a SharePoint list using PowerApps, I'm not going to rehash that here, but basically it involves connecting to your SP List as a data source in PowerApps, and then there are several functions (Update/Patch/SubmitForm/probably more) that can make changes to the SP List.

 

You can use the Now() function in Powerapps to return the current date/time, or Today() to return the current date. Those can be passed to your SharePoint List (or to your Flow, although it may end up being easier to do everything through PowerApps, unless there are other steps in your flow which haven't been mentioned in this discussion 🙂 )

 

For the color changing, the code is looking up the date is stored in the SP List (or the last saved date- that's a little more difficult, but still do-able), and then doing a comparison (using the DateAdd function) to see if the stored date is more/less than an arbitrary number of days. (5 in the example above).

 

Basically:

  1. Button is pushed in PowerApps
  2. This stores the date (and user name who pushed the button) in SP, either via Flow, or in PowerApps
  3. The "Fill" variable for the button is not a static value, but a formula
    1. Compares the current date (using the Today() function) to the stored date in SP
    2. If Stored Date is more than 5 days before Current Date, button is green
    3. If Stored Date is less than 5 days before Current Date, button is red

As for starting a Flow from a button in PowerApps, I haven't done it, but a quick google search should help you out there.

kziegler
Frequent Visitor

So I've managed to achieve everything except for changing the color based on the date, I have no clue what code I would use as I tried using your previous example however, I'm still not sure how to grab the previous date stored. If you have any further tips on that it would be much appreciated, but its totally okay if not.

abrae005
Kudo Collector
Kudo Collector

Again, I don't know your complete setup. I'm going to assume you're using a SharePoint list to share the data.

 

I created a test list, called "Powerapp_Test", and created 3 columns - Title (default column), Date_Button_Pushed (Date), Button_Pusher_Username (Text).

 

In Powerapps, click on the Data tab, then click Add Data

abrae005_0-1657658464788.png

 

Select "SharePoint" as a Data Source, and find your SharePoint site, then choose the correct list.

 

Then, you'll need to find the latest date in the SharePoint list. I threw a label on the screen, and used this formula. (This is helpful when building the app, it'll help you see the data better, but you don't need to)

 

First(Sort(Powerapp_Test, Date_Button_Pushed, Descending)).Date_Button_Pushed

 

 

I also threw another label, to show the date 5 days ago, using this formula

 

DateAdd(Today(), -5, Days)

 

 

Here's an If Statement that will show if the Last Date is more recent than 5 days ago:

 

If(First(Sort(Powerapp_Test, Date_Button_Pushed, Descending)).Date_Button_Pushed > DateAdd(Today(), -5, Days), "Yes", "No")

 

 

Then, select your button, and modify the "Fill" property to be the following

 

If(First(Sort(Powerapp_Test, Date_Button_Pushed, Descending)).Date_Button_Pushed > DateAdd(Today(), -5, Days), RGBA(255,0,0,1), RGBA(0,255,0,1))

 

 

The format of the IF statement is If(Logical Test, True Value, False Value). So, in the first If statement above, we are comparing the most recent date (that's the big long formula with first/sort) to 5 days ago (the dateadd formula), and returning the text values Yes or No if the statement is true or false. That's good for the label, but for the button fill, we want to set the color using RGBA values - RGBA is Red, Green, Blue, Alpha. Leave the alpha at 1. I used (255,0,0,1) for the Red (the button HAS been pressed within the past 5 days) and (0,255,0,1) for the Green (last button push is more than 5 days ago).

 

Do a google search for RGB color picker, and put in (255,0,0) or (0,255,0) to see what colors those correspond to.

 

abrae005_1-1657659980640.png

 

You will probably also want to add a Refresh(Powerapp_Test) as part of your button's on-select action. That will make sure it pulls the latest date after you push the button.

 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (966)