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

PowerApps: NewForm Function

Hello Community,

 

How NewForm function in PowerApps works? 

 

As per my understanding the function ignores Form Control's Item Property, and will take default values of form data source.

 

In my case, PowerApps --> Edit Form --> Set App Onstart() --> NewForm(Form1)

 

Set Sharepoint as datasource, Add 2 field 1 number[Set default value 0] and second date[default date today].

 

Add this 2 field in data source and run app. 

 

Form populate number field with default value 0 but it won't works on date field?

 

So how the function works?

 

Thanks,

Bansari Pandya.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft
Microsoft

Hi @Bansari_Pandya ,

What is the Item property of your Form1? Have you set its item property as “Defaults(SPList)”?

Based on the information described in the Microsoft documentation, each field should be populated with its default value in NewForm():

“In FormMode.New mode, the contents of the Form control's Item property are ignored, and the default values of the Form's DataSource property populate the form.”

I did a test in my app, according to the conditions you provided, also set my Form’s Item property as “Defaults(Mylist)”. When I run my app, I meet the same situation as you: Number field is populated with default value 0, but date field isn't populated with today().

Then I add a submit button: “SubmitForm(MyForm)” , then add a record, only fill in Title:

v-albai-msft_0-1611108347345.png

Go to my SP list, I found that the date of this record has been filled with the default value(today()):

v-albai-msft_1-1611108347347.png

Double check my form, I found that the value inside Date is a Placeholder, it is not a value populated by default value. When view the “InputTextPlaceholder” property of the date field, Text is set as a date value:

v-albai-msft_2-1611108347350.png

So set this property as below and everything is ok(just replace Date(2001,12,31) with Today()😞

 

If(IsBlank(Self.SelectedDate), Text(Today(), Self.Format, Self.Language))

 

Best Regards,

Allen

View solution in original post

2 REPLIES 2
Super User II
Super User II

Hi @Bansari_Pandya 

You almost have it right.  NewForm() does not require that the Item property be populated because until the data is saved, there is no Item.  If you want to create a new record when the app starts, you could use the Patch() function instead of a form to create the record.  It would be Patch(SPlist, Defaults(SPlist),{numberfield:0, datefield:Today()). FYI, if you happened to close the app and reopen it the same day, you would create another record. 

Microsoft
Microsoft

Hi @Bansari_Pandya ,

What is the Item property of your Form1? Have you set its item property as “Defaults(SPList)”?

Based on the information described in the Microsoft documentation, each field should be populated with its default value in NewForm():

“In FormMode.New mode, the contents of the Form control's Item property are ignored, and the default values of the Form's DataSource property populate the form.”

I did a test in my app, according to the conditions you provided, also set my Form’s Item property as “Defaults(Mylist)”. When I run my app, I meet the same situation as you: Number field is populated with default value 0, but date field isn't populated with today().

Then I add a submit button: “SubmitForm(MyForm)” , then add a record, only fill in Title:

v-albai-msft_0-1611108347345.png

Go to my SP list, I found that the date of this record has been filled with the default value(today()):

v-albai-msft_1-1611108347347.png

Double check my form, I found that the value inside Date is a Placeholder, it is not a value populated by default value. When view the “InputTextPlaceholder” property of the date field, Text is set as a date value:

v-albai-msft_2-1611108347350.png

So set this property as below and everything is ok(just replace Date(2001,12,31) with Today()😞

 

If(IsBlank(Self.SelectedDate), Text(Today(), Self.Format, Self.Language))

 

Best Regards,

Allen

View solution in original post

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Top Solution Authors
Top Kudoed Authors
Users online (99,894)