cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
omainesi
Frequent Visitor

How do I set the defaultselecteditems of a combobox using a value from a choice set

Hi,

 

I'm struggling to set the defaultselecteditems property of my combobox with a value from a choice set that I have.

 

I'm using Microsoft Dataverse for storing my app data.

 

Here's the code I have under the DefaultSelectedItems property:

 

If(
    DataCardValue5.Selected.Value = [@'Timesheet Type'].Holiday,
    ["30"],
    [Parent.Default]
)

 

Essentially this is saying if the user selects the value Holiday in a separate combobox, then set the DefaultSelectedItems of this combobox to "30", else Parent.Default

 

Now when I run the app and select "Holiday" the combobox appears to be set as 30:

 

Capture.PNGBut it's just added the text "30" to the box, it hasn't actually selected the choice value 30. If I click the dropdown arrow for the combobox you can see that the "30" is not actually selected:

 

Capture 2.PNG

 

Here is what the above image would look like if the 30 was actually selected:

Capture 3.PNG

 

When I submit the form the field is also left blank. How do I write the above code so that it actually selects the choice set "30" and saves it to the record?

 

1 ACCEPTED SOLUTION

Accepted Solutions

Thanks for your reply, I tried your suggestion but was unable to get it to work. The solution didn't have any errors, but on form submit the field was still empty.

 

I've persevered and spent another 2 hours on this tonight, taking my grand total on this problem to about 6 hours 🙄 but I've finally figured it out:

 

 

 

If(
    DataCardValue5.Selected.Value = [@'Timesheet Type'].Holiday,
    [[@'Start Time Minute'].'30'],
    [Parent.Default])

 

 

 

So for anyone who comes across this in the future, here's a breakdown:

 

If(DataCardValue5.Selected.Value = [@'Timesheet Type'].Holiday,

The above checks the selected value of a combobox to see if the value "Holiday" is selected, if this statement is true then it:

 

[[@'Start Time Minute'].'30'],

The above sets the value of the combobox in question to '30' (@'Start Time Minute' is the name of my choice set for this combobox and '30' is one of the choices).

 

[Parent.Default])

Else it sets the combobox to Parent.Default

 

A final point to note was that I mentioned in the original post that my code only appeared to be adding the text "30" to the combobox, and when I clicked the arrow to view all the options, '30' wasn't highlighted. With the above code, it was still not highlighting the '30' as selected, but onsubmit it was saving "30" to the record. Strange, but to be honest I'm just happy it now works.

 

View solution in original post

2 REPLIES 2
StalinPonnusamy
Super User
Super User

Try this

Set DefaultSelectedItems for combobox is

 

If(condition,{Value:30},{Value:ThisItem.'ColumnName'.Id})

 

 

Example (Actual and changed using default)

StalinPonnusamy_0-1627662727519.png

 

Thanks for your reply, I tried your suggestion but was unable to get it to work. The solution didn't have any errors, but on form submit the field was still empty.

 

I've persevered and spent another 2 hours on this tonight, taking my grand total on this problem to about 6 hours 🙄 but I've finally figured it out:

 

 

 

If(
    DataCardValue5.Selected.Value = [@'Timesheet Type'].Holiday,
    [[@'Start Time Minute'].'30'],
    [Parent.Default])

 

 

 

So for anyone who comes across this in the future, here's a breakdown:

 

If(DataCardValue5.Selected.Value = [@'Timesheet Type'].Holiday,

The above checks the selected value of a combobox to see if the value "Holiday" is selected, if this statement is true then it:

 

[[@'Start Time Minute'].'30'],

The above sets the value of the combobox in question to '30' (@'Start Time Minute' is the name of my choice set for this combobox and '30' is one of the choices).

 

[Parent.Default])

Else it sets the combobox to Parent.Default

 

A final point to note was that I mentioned in the original post that my code only appeared to be adding the text "30" to the combobox, and when I clicked the arrow to view all the options, '30' wasn't highlighted. With the above code, it was still not highlighting the '30' as selected, but onsubmit it was saving "30" to the record. Strange, but to be honest I'm just happy it now works.

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (2,866)