cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Update Date picker to current date if the date field is blank

I have a date field in the NewForm view that will serve as the date the form was submitted. I want this date field to be autopopulated to the current date and not change after the form is submitted. My logic is when the newform view opens and if the date field is blank, then set the date to Today(). I have the following formula as the DefaultDate:
If(IsBlank(ThisItem.Date),Today())
This appears to work in the PowerApps Preview and when I publish and play the app via a web browser but when I try to test the app on a device, the date is not populating to the current date. What am I missing?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Memorable Member
Memorable Member

Re: Update Date picker to current date if the date field is blank

Sorry you have to use 

if(FormGeneralInfoNS.Mode=New,Today(),ThisItem.Date)

 

Théo

View solution in original post

7 REPLIES 7
Highlighted
Memorable Member
Memorable Member

Re: Update Date picker to current date if the date field is blank

Hi @PowerAid,

 

By doing so you're only populated the datefield when this one is blank. 

You should try playing with the FormMode like this :

DatePicker.DefaultDate : If(Form1.FormMode=New,Today(),ThisItem.Date)

Theo

Highlighted
Helper II
Helper II

Re: Update Date picker to current date if the date field is blank


@tchin-nin wrote:

Hi @PowerAid,

 

By doing so you're only populated the datefield when this one is blank. 

You should try playing with the FormMode like this :

DatePicker.DefaultDate : If(Form1.FormMode=New,Today(),ThisItem.Date)

Theo


Hi Theo,

 

In regard to your suggestion, I don't understand where and what to type.  Do I select the date field, then select the DefaultDate property dropdown and then type the following?

If(Form1.FormMode=New,Today(),ThisItem.Date

 

Highlighted
Memorable Member
Memorable Member

Re: Update Date picker to current date if the date field is blank

Yes exactly, you set this formula on the DefaultDate property of your datepicker control.

The formula says, if the form is a new item form, then set the date to Today(). If not (so if it is an Edit or a View form) set the date to the current item date (which will be the date saved when the item has been created). 

 

If you don't want your users to change that date you can just hide the DataCard by setting the Visibile property to : false. 

 

Théo

Highlighted
Helper II
Helper II

Re: Update Date picker to current date if the date field is blank


@tchin-nin wrote:

Yes exactly, you set this formula on the DefaultDate property of your datepicker control.

The formula says, if the form is a new item form, then set the date to Today(). If not (so if it is an Edit or a View form) set the date to the current item date (which will be the date saved when the item has been created). 

 

If you don't want your users to change that date you can just hide the DataCard by setting the Visibile property to : false. 

 

Théo


I follow you but it doesn't accept that syntax.  My form name is FormGeneralInfoNS and I'm pretty sure it is in the New form mode.  When I type: If(FormGeneralInfoNS   it doesn't allow me to add a .FormMode right after that.  What I mean is that .FormMode is not a suggested option as I try and add it.  If i force it in the formula box, it will not accept it.  The closest formula it will accept is: If(FormMode=New, Today(), ThisItem.date)  Unfortunaltely, that does not produce a change of any kind.

Highlighted
Memorable Member
Memorable Member

Re: Update Date picker to current date if the date field is blank

Sorry you have to use 

if(FormGeneralInfoNS.Mode=New,Today(),ThisItem.Date)

 

Théo

View solution in original post

Highlighted
Helper II
Helper II

Re: Update Date picker to current date if the date field is blank


@tchin-nin wrote:

Sorry you have to use 

if(FormGeneralInfoNS.Mode=New,Today(),ThisItem.Date)

 

Théo


That worked!  Thanks for the help.  I'm a PowerApps newbie.  Looking to use this to replace our InfoPath forms.   Lots of learning ahead.  Your help is much appreciated!

Highlighted
Memorable Member
Memorable Member

Re: Update Date picker to current date if the date field is blank

Glad to help you !
Feel free to look for answer and/or ask some questions in this community to learn how to deal with PowerApps 🙂

Théo

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (9,912)