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

Text field to show last time a button was used?

Hi,

Unsure if this is possible.

I've created a basic app to allow users to select topics then click a notify button that then sends a premade message to a Teams group chat.

 

What I was wondering, would it be possible to do something like this

 

User presses button, message sent like normal

Then, Date and time sent to a Sharepoint List

Any time the app is started by any user, it checks for the latest entry on this SharePoint list

Displays under the button, "Notice last sent <insert date and time>

 

Any help would be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Matren
Responsive Resident
Responsive Resident

Hi @JRRFG,

 

Combined solution per your request:

 

This is possible. Add the following code to your OnSelect property for the nofity button.

 

Step 1: Get the DateTime. This code will capture the DateTime in the variable gblSaveDateTime after your Notify button is clicked.

Set(gblSaveDateTime, Now())

 

Step 2: Populate the DateTime in SharePoint list. You can then use the DateTime variable to populate a value in your SharePoint list using a Patch command or place the value in a form and SubmitForm.

 

Patch(SPListName, Defaults(SPListName), {SPListColumnName: gblSaveDateTime})

More info about Patch: https://www.matthewdevaney.com/7-ways-to-use-the-patch-function-in-power-apps-cheat-sheet/#1.-Create...

 

Step 3: Retreive the value from the SharePoint List and place it in another variable (e.g. gblDisplayDateTime). You can retrieve the value from the SharePoint list by using a Lookup command or PowerAutomate flow to get the value and place it in the gblDisplayDateTime variable Set in the OnVisible property for the screen where your button is located. When the screen becomes visible, the variable will be populated with the most recent DateTime in your SharePoint list. (As an aside, it will be interesting to compare the gblDisplayDateTime value to the Created value for the record in your SharePoint list. How close are they?)

 

Set(gblDisplayDateTime, First(Sort(SPListName,ID,Descending)).Created)

Add your SPListName to this code and it should give you the last created date/time for the record in the list. You might also consider referencing the time you clicked the button (stored under Title?) and add TITLE instead of Created to the end. It will be interesting to see how close these times are to each other.

 

This gblDisplayDateTime variable will populate every time the screen becomes visible (i.e. upon app start, navigate back to this screen from another screen, etc.). If you ONLY want to populate it at app start, you can add the following:

If(IsBlank(Set(gblDisplayDateTime, First(Sort(SPListName,ID,Descending)).Created)))

 

4. In label that is placed below the Notify Button, you can place the following in the Text property to show the DateTime.

"Notice last sent " & gblDisplayDateTime

(note the space between "sent" and the final ".  

 

Let me know how it goes.

 

Best Wishes,

 

Matren

 

--------------------------------------------------------------------------------------------

Find this post helpful, give it a Thumbs Up

Solved your problem, click Accept as Solution so others can find it

View solution in original post

8 REPLIES 8
Matren
Responsive Resident
Responsive Resident

Hi @JRRFG,

 

This is possible. Add the following code to your OnSelect property for the nofity button.

 

Step 1: Get the DateTime. This code will capture the DateTime in the variable gblSaveDateTime after your Notify button is clicked.

Set(gblSaveDateTime, Now())

 

Step 2: Populate the DateTime in SharePoint list. You can then use the DateTime variable to populate a value in your SharePoint list using a Patch command or place the value in a form and SubmitForm.

 

Step 3: Retreive the value from the SharePoint List and place it in another variable (e.g. gblDisplayDateTime). You can retrieve the value from the SharePoint list by using a Lookup command or PowerAutomate flow to get the value and place it in the gblDisplayDateTime variable Set in the OnVisible property for the screen where your button is located. When the screen becomes visible, the variable will be populated with the most recent DateTime in your SharePoint list. (As an aside, it will be interesting to compare the gblDisplayDateTime value to the Created value for the record in your SharePoint list. How close are they?)

 

4. In label that is placed below the Notify Button, you can place the following in the Text property to show the DateTime.

"Notice last sent " & gblDisplayDateTime

(note the space between "sent" and the final ".  

 

Let me know how it goes.

 

Best Wishes,

 

Matren

 

--------------------------------------------------------------------------------------------

Find this post helpful, give it a Thumbs Up

Solved your problem, click Accept as Solution so others can find it

JRRFG
Frequent Visitor

Hi Matren,

 

Can you please help on step 2?

 

I have the following on the Notify Button;

WHSNotification.Run(DatePicker1, TextInput3);
Set(gblSaveDateTime, Now());

 

I have a sharepoint list setup and connected to the app; called 'DatePressed Test'

I'm unsure how to configure the Patch(

Matren
Responsive Resident
Responsive Resident

Hi @JRRFG,

 

Sure, you can use the following code in the OnSelect property for your button:

 

Patch(SPListName, Defaults(SPListName), {SPListColumnName: gblSaveDateTime})

More info about Patch: https://www.matthewdevaney.com/7-ways-to-use-the-patch-function-in-power-apps-cheat-sheet/#1.-Create...

 

Let me know how it goes.

 

Best Wishes,

 

Matren

--------------------------------------------------------------------------------------------

Find this post helpful, give it a Thumbs Up

Solved your problem, click Accept as Solution so others can find it

 

JRRFG
Frequent Visitor

Hi @Matren ,

 

Sorry for the delay. So the patch to the sharepoint list is now working.

Now I'm stuck on step 3. I'm trying to use lookup on detailscreen1, onvisable, however I'm unsure how to complete the lookup as the list only has 1 column (Title) and now the date underneath.

 

Can you please assist with the correct code for pulling the information back into the app from the sharepoint list and how to set it as the gblDisplayDateTime variable Set?

Matren
Responsive Resident
Responsive Resident

Hi @JRRFG,

 

SharePoint Lists have several columns that are automatically generated. One of them is called "Created" so you will want to lookup on the last record that had the latest Created value and return it. To easily see the Created value, I first recommend you add the Created column to your list's view. You can do this by going to the list in SharePoint and clicking on "Edit Current View." Then make sure "CREATED" is checked.

 

Next, I recommend adding the following code in your app (under your 1st Screen OnVisible property) to do the lookup:

 

Set(gblDisplayDateTime, First(Sort(SPListName,ID,Descending)).CREATED)

Add your SPListName to this code and it should give you the last created date/time for the record in the list. You might also consider referencing the time you clicked the button (stored under Title?) and add TITLE instead of CREATED to the end. It will be interesting to see how close these times are to each other.

 

This gblDisplayDateTime variable will populate every time the screen becomes visible (i.e. upon app start, navigate back to this screen from another screen, etc.). If you only want to populate it at app start, you can add the following:

 

If(IsBlank(Set(gblDisplayDateTime, First(Sort(SPListName,ID,Descending)).CREATED)))

The first time the app starts the variable will be blank and it will populate. After that it will never run until the app is started again.

 

Last, follow the guidance for Step 4 above.

 

Let me know how it goes.

 

Best Wishes,

Matren

-------------------------------------------------------------------------------------------

Find this post helpful, give it a Thumbs Up

Solved your problem, click Accept as Solution so others can find it

JRRFG
Frequent Visitor

Hi @Matren ,

 

I had to change CREATED to Created but it now works!!!

Thank you so much mate!

 

If you have the time did you want to combine your steps into one post and i'll mark as solution so people can find it in the future?

 

Thanks again mate!

Matren
Responsive Resident
Responsive Resident

Hi @JRRFG,

 

Combined solution per your request:

 

This is possible. Add the following code to your OnSelect property for the nofity button.

 

Step 1: Get the DateTime. This code will capture the DateTime in the variable gblSaveDateTime after your Notify button is clicked.

Set(gblSaveDateTime, Now())

 

Step 2: Populate the DateTime in SharePoint list. You can then use the DateTime variable to populate a value in your SharePoint list using a Patch command or place the value in a form and SubmitForm.

 

Patch(SPListName, Defaults(SPListName), {SPListColumnName: gblSaveDateTime})

More info about Patch: https://www.matthewdevaney.com/7-ways-to-use-the-patch-function-in-power-apps-cheat-sheet/#1.-Create...

 

Step 3: Retreive the value from the SharePoint List and place it in another variable (e.g. gblDisplayDateTime). You can retrieve the value from the SharePoint list by using a Lookup command or PowerAutomate flow to get the value and place it in the gblDisplayDateTime variable Set in the OnVisible property for the screen where your button is located. When the screen becomes visible, the variable will be populated with the most recent DateTime in your SharePoint list. (As an aside, it will be interesting to compare the gblDisplayDateTime value to the Created value for the record in your SharePoint list. How close are they?)

 

Set(gblDisplayDateTime, First(Sort(SPListName,ID,Descending)).Created)

Add your SPListName to this code and it should give you the last created date/time for the record in the list. You might also consider referencing the time you clicked the button (stored under Title?) and add TITLE instead of Created to the end. It will be interesting to see how close these times are to each other.

 

This gblDisplayDateTime variable will populate every time the screen becomes visible (i.e. upon app start, navigate back to this screen from another screen, etc.). If you ONLY want to populate it at app start, you can add the following:

If(IsBlank(Set(gblDisplayDateTime, First(Sort(SPListName,ID,Descending)).Created)))

 

4. In label that is placed below the Notify Button, you can place the following in the Text property to show the DateTime.

"Notice last sent " & gblDisplayDateTime

(note the space between "sent" and the final ".  

 

Let me know how it goes.

 

Best Wishes,

 

Matren

 

--------------------------------------------------------------------------------------------

Find this post helpful, give it a Thumbs Up

Solved your problem, click Accept as Solution so others can find it

Matren
Responsive Resident
Responsive Resident

Hi @JRRFG,

 

Great, I'm glad it is resolved!

 

Feel free to give kudos (thumbs up) on any post in this chain you feel was helpful.

 

Thanks and have a great week,

Matren

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,749)