cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AAallday
Helper I
Helper I

Button to populate date/time picker with now timestamp

Hello, I have a canvas form for an SPO list. in the list I have "Accepted DateTime", a date/time field (not required).

 

Is it possible to add a button to the form so that when I want to populate "Accepted DateTime", it automatically fills the fields with the current date and time? (the reason, I want to save users (a little) time from having to select the date, and hours and min manually if possible)

AAallday_0-1643306284897.png

 

The field should be blank until populated, then that value saved (unless overwritten).

 

Any thoughts?

 

(I am not very powerapps skilled)

 

Thank you in advance

11 REPLIES 11
RandyHayes
Super User
Super User

@AAallday 

On your button, use the following formula:

UpdateContext({lclNowTime: Now()})

Since you mention this is a form, then your Default properties on the controls should be as follows:

For the DatePicker - DefaultDate:

   Coalesce(lclNowTime, Parent.Default)

For the Hour Time Dropdown Default:

  Text(Hour(Coalesce(lclNowTime, Parent.Default)),"00")

For the Minute Time Dropdown Default:

  Text(Minute(Coalesce(lclNowTime, Parent.Default)),"00")

 

I would recommend performing an UpdateContext({lclNowTime: Blank()}) in either the OnSuccess action formula of the form, or in your OnHidden or OnVisible action of the screen.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
AAallday
Helper I
Helper I

Hi @RandyHayes  thanks for the email is lclnowtime the card name? or the field name?

 

I tried both, in the onselect field, but neither worked. I even tried with single quote ('accepteddatetime').

 

Do i need to recreate the date time fields directly (I currently have the fields that are present when i "add field")?

RandyHayes
Super User
Super User

@AAallday 

lclNowTime is a context variable that is assigned in the OnSelect of your button.

The formulas I provided should be used as they are without alteration.  

 

Make those changes and if you still have issues, let me know what they are.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

I have tried everything you detailed, but my button still doesn't make any change to the date picker. To back up

1. i added the date column to the spo list

2. i added the field to my edit form (canvas app)

3. while in the date card i added a button (input)

4. added the formulas as described

 

No success. 

 

the formula you provided "knows" to add the now values to the date picker field inherently? is there something i have to do first?

 

(Thank you again sir)

RandyHayes
Super User
Super User

@AAallday 

To validate that what I provided is accurate (as it was all from memory and experience) I did put this into a form with a date/time picker.  All worked perfectly.

 

So, let's explore your scenario.  Can you provide a screen shot of what you have at this point.  And, let me know (you can do this in screenshots too) the formulas you have on the DatePicker DefaultDate property, the Default of the Dropdowns and the OnSelect of your button.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

Button:

AAallday_0-1643321736261.png

Date picker: 

AAallday_1-1643321747007.png

 

Hour:

AAallday_2-1643321765716.png

 

Minute:

AAallday_3-1643321773871.png

 

edit Screen:

AAallday_4-1643321796201.png

 

RandyHayes
Super User
Super User

@AAallday 

Okay...that is all looking good.

So you're stating though that when you click on your button, nothing happens?

 

OH...before we go to far down a rabbit hole...

What is your DefaultMode of the Form and the Item property of the form?

If it is in Edit mode, then you need to supply a valid record for the Item property of the Form.  Same for View mode...need a valid Item record.

 

So either set the form DefaultMode to New, or provide a valid record for the Item or set the Item to Defaults(yourDataSource).

Otherwise...the UpdateContext will not work!  (this is a current form issue)

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes  this is on my edit form and my defaultmode is "formmode.edit" ... is this what i should change to "Defaults(datasource)"? this will pull entry i needed to edit?

RandyHayes
Super User
Super User

@AAallday 

What is your Item property of the form?  That is what you would set, or change the form DefaultMode to New.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (2,495)