cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PowerAid
Level: Powered On

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
tchin-nin
Level 10

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

7 REPLIES 7
tchin-nin
Level 10

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

PowerAid
Level: Powered On

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

 

tchin-nin
Level 10

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

PowerAid
Level: Powered On

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.

tchin-nin
Level 10

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

PowerAid
Level: Powered On

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!

tchin-nin
Level 10

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 Smiley Happy

Théo

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 183 members 4,156 guests
Recent signins:
Please welcome our newest community members: