Power Apps – Set/Reset values in Choice and Lookup Columns

Hello Folks, In this #PowerGuideTip, I am going to share a Tip to set/reset value in Choice (earlier name: Option Set) and Lookup field of Microsoft Dataverse in Power Apps.

Requirements

I have came across numerous business requirements and have also seen folks asking in community about setting/resetting value in choice (dropdown/optionset) and lookup field on button click. This article helps you fulfill following business requirements in Power Apps:

  • Set value in Choice (Option Set) field of Microsoft Dataverse on-demand in Edit form.
  • Set value in Lookup field on-demand in Edit form.
  • Autopopulate value in Choice field in Edit form.
  • Autopopulate value in Lookup field in Edit form.
  • Reset/Clear Choice and Lookup fields in Edit form.

Note: Power Apps use Combo Box control to render Choice and Lookup type fields in Power Apps Edit form.

Prerequisite

I already have a Power Apps Canvas app, where I have added Edit Form of Account table (Microsoft Dataverse). And the form has following controls:

Solution

For Lookup:

In order to set/reset the value in lookup field, I have used a global variable called ‘gvar_primaryContact’, that will hold the value I want to set on click of ‘Set Lookup’ button. Since it’s a lookup field, therefore you need to retrieve the record first from dataverse using Lookup function.

And finally, you need to set that global variable on ‘defaultselecteditem‘ property of the combo box.

Step 1: PowerFx expression onSelect property of ‘Set Lookup’ button.
Step 2: PowerFx expression onSelect property of ‘Reset Lookup’ button.
Step 3: PowerFx expression on DefaultSelectedItems property of ‘Combo Box’ control.

For Choices (Option Set):

In order to set/reset the value in Choice (Option Set) field, I have used a global variable called ‘gvar_businessType’, that will hold the value I want to set on click of ‘Set Dropdown’ button. Since it’s a Choice field, therefore you need to first retrieve its option value from dataverse using Lookup function.

Step 1: PowerFx expression onSelect property of ‘Set Dropdown’ button.
Step 2: PowerFx expression onSelect property of ‘Reset Dropdown’ button.
Step 3: PowerFx expression on DefaultSelectedItemsSelect property of ‘Set Dropdown’ button.

Important Tip: In this example, I have set/reset value on button click. If you want to autopopulate the value as soon as form loads, you can use the PowerFx expression (which i have written on onSelect property of the button) directly on DefaultSelectedItems property of the Combo Box. (See below)

Hope you find this #PowerGuideTip helpful. Stay tuned for further useful tips.

Advertisement

Published by arpitpowerguide

My name is Arpit Shrivastava, who is a Microsoft MVP in the Business Applications category. I am a Microsoft Dynamics 365 and Power Platform enthusiast person who is having a passion for researching and learning new things and acquiring immense knowledge. I am providing consistent help, support, and sharing my knowledge through various Social Media Channels along with my Personal Blog, Microsoft Community, conducting online training and attending various 365 Saturday Events worldwide and sharing the best Solutions to the readers helping them achieve their goals and objectives in Customer Relationship Space.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: