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:
But 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:
Here is what the above image would look like if the 30 was actually selected:
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?
Solved! Go to Solution.
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.
Try this
Set DefaultSelectedItems for combobox is
If(condition,{Value:30},{Value:ThisItem.'ColumnName'.Id})
Example (Actual and changed using default)
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.