Setting a Default Dataverse LookUp value in Canvas Apps can give a slick user experience.  I’ll demonstrate using the example of a simple Asset Tracking app.   The app has just 2 screens fronting two tables.  The Location table has a one-to-many relationship with Assets, meaning one Location can have many Assets 

The Data Model

The Screens

Both screens can consist of either a Form or seperate controls writing to Dataverse using the Patch function

On screen 1, the 3 columns in the Location table are presented.  As well as writing the entered data to Dataverse, the ‘Submit’ button also saves the unique ‘LocationName’ to a variable called gblLocation (see below) and then navigates to screen 2

Set(gblLocation,txtLocationName.Text)

Default Dataverse Lookup Value

On Screen 2, gblLocation (shown above with a value of ‘London’) is applied with the LookUp function as the DefaultSelectedItems property of the Dropdown for the ‘AssetLocation’ column displayed in grey

LookUp(Assets,AssetLocation.LocationName=gblLocation)

In the app above, the user has the opportunity to change the default value in the ‘AssetLocation’ Dropdown.  As an alternative, if you always wanted the Asset created on Screen 2 to be associated with the Location entered on screen 1, locking down the DisplayMode property of the Dropdown box or setting it’s Visible, property to false, would prevent any changes being made

Its important to note that the ‘DefaultSelectedItems’ property should be used, not the ‘Default’ property

And that’s it. The Lookup Dropdown is pre-populated.  Nice and simple with no delegation issues

A neat feature of this technique is that if there are certain circumstances where you want to force the user to select a Location, change the value of the gblLocation variable to Blank().  This will make DefaultSelectedItems empty.  Always better to have the user make a concious decision and select a Location (which they have to do if the default is blank) rather than risk them mistakenly using the first selection presented in the dropdown

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top