cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
365-Assist
Advocate III
Advocate III

Tip - How to set field defaults in PowerApps Model Driven Dataverse

These are instructions on how to set fields (both Text and Lookup) defaults on a Model PowerApp form.

The Street is a text field and the Suburb and States are both lookups.

365-Assist_0-1620012292240.png

Unfortunately there is no way to set defaults for Text and Lookups in the standard form design. Therefore some Java Script will be required. For the example above here is my JS in full.

 

365-Assist_1-1620012319950.png

 

1 ACCEPTED SOLUTION

Accepted Solutions


@365-Assist wrote:

Thanks for your replies. 

 

The difference between using the Business Rule and JS is that the Business Rule activates after the user saves the record. Whilst the JS activates as soon as the new page is loaded.


@365-Assist  that is not correct business rules run on form load and on attribute change.  On form load the business rule does not distinguish between new/create or edit forms and will trigger.  If you need something to only trigger on the new/create form and not the edit form, then in the BR condition you use a field that you know will always not be populated prior to the record being created (hence, the use of createdon to detect that the form is a create vs edit/readonly etc).  We do this type of thin all the time with Business Rules.

 

JS certainly has more flexibility than a BR (as there are many limitations with BRs) but for the example provided it can be done with a BR.

View solution in original post

6 REPLIES 6
v-albai-msft
Community Support
Community Support

Hi @365-Assist ,

Thanks for your sharing. Someone must be benefited from your code.

Best regards,

Allen

Fubar
Solution Sage
Solution Sage

If all you are doing is 'defaulting' to a set value you can do both Lookup and Text in a Business Rule - no need for JavaScript (only where there is more complexity beyond the Business Rules capability).

 

For someone new, also need to be aware that the Entity in the original post is a custom entity.  On an out of the box Account or Contact entity you would also want to do some additional population - populating the out of the box field that the lookup is replacing when the lookup is populated/cleared - this is important as the Composite Address fields (shows the address block in 1 field) do not show custom fields., and the Bing map control also only works with the standard fields

 

In addition, usually defaulting is only wanted on a Create form (not an Edit form), in JS you may check for .formType()  in a Business Rule add the CreatedOn field to the Form (can be hidden or in the Footer etc) and check if it contains data

 

EricRegnier
Super User II
Super User II

Cheers for that, note that there are also no code/low-code alternatives such as with Power Automate and Business Rules. Suggest to submit that feature though (if it doesn't already exists) at: https://powerusers.microsoft.com/t5/Power-Apps-Ideas/idb-p/PowerAppsIdeas and I'll vote 🙂

365-Assist
Advocate III
Advocate III

Thanks for your replies. 

 

The difference between using the Business Rule and JS is that the Business Rule activates after the user saves the record. Whilst the JS activates as soon as the new page is loaded.


@365-Assist wrote:

Thanks for your replies. 

 

The difference between using the Business Rule and JS is that the Business Rule activates after the user saves the record. Whilst the JS activates as soon as the new page is loaded.


@365-Assist  that is not correct business rules run on form load and on attribute change.  On form load the business rule does not distinguish between new/create or edit forms and will trigger.  If you need something to only trigger on the new/create form and not the edit form, then in the BR condition you use a field that you know will always not be populated prior to the record being created (hence, the use of createdon to detect that the form is a create vs edit/readonly etc).  We do this type of thin all the time with Business Rules.

 

JS certainly has more flexibility than a BR (as there are many limitations with BRs) but for the example provided it can be done with a BR.

View solution in original post

Ok I see now. I made a test and got it working.

 

Always fun to learn something new the hard way.😀

 

 

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (47,209)