Dear all,
I would like to set an IF condition for a Combobox field, which would show a filtered value as the default selected value if Form.Mode = New or parent.default if otherwise.
First I set the filter for the available items in the Library Combobox. The library Combobox Items =
Then. I have tried the following formula for Library combobox's DefaultSelectedItems, which show no error, but also return no value:
If(varFormMode = FormMode.New,
Distinct(
Filter(
MTDemoSPList2,
Books = cmb_Demo1.Selected.Result
).Library
,Parent.Default))
Could anyone please advise if there is a logical error in the function above?
Solved! Go to Solution.
@Anonymous
Choice columns have records with a Value column. Your formulas are all producing tables that have Result columns. This will not match. Comboboxes have to have matching values.
So, since you are using a combobox, your Items property should be changed to the following:
RenameColumns(
Sort(
Distinct(
Filter(MTDemoSPList,
Factory = cmb_Demo1.Selected.Result
),
Library
),
Result
),
"Result",
"Value"
)
Your DefaultSelectedItems property (not the Default) of the Combobox should be:
If(varFormMode = FormMode.New,
RenameColumns(
Distinct(
Filter(
MTDemoSPList2,
Books = cmb_Demo1.Selected.Result
),
Library
),
"Result",
"Value"
),
Parent.Default
)
Now, your combobox will not only have matching schemas in the defaults and the items, but it will now allow you to Update the underlying record with the .SelectedItems property of the combobox as it will also match the required record type for a Choice column.
If I use ThisItem.'Library' instead of Parent.Default, everything seems to work..
@Anonymous
Your formula has a mistake in it, please consider the following formula:
If(varFormMode = FormMode.New,
Distinct(
Filter(
MTDemoSPList2,
Books = cmb_Demo1.Selected.Result
),
Library
),
Parent.Default
)
However, the bigger part will be that the Parent.Default will most likely not match your Items. What is the underlying column type of the field you are working with?
I hope this is helpful for you.
Ho @RandyHayes. Thanks! The underlying column type is Choice. Why shouldn't parent.default match the Items? Is it because of the column type?
@Anonymous
Choice columns have records with a Value column. Your formulas are all producing tables that have Result columns. This will not match. Comboboxes have to have matching values.
So, since you are using a combobox, your Items property should be changed to the following:
RenameColumns(
Sort(
Distinct(
Filter(MTDemoSPList,
Factory = cmb_Demo1.Selected.Result
),
Library
),
Result
),
"Result",
"Value"
)
Your DefaultSelectedItems property (not the Default) of the Combobox should be:
If(varFormMode = FormMode.New,
RenameColumns(
Distinct(
Filter(
MTDemoSPList2,
Books = cmb_Demo1.Selected.Result
),
Library
),
"Result",
"Value"
),
Parent.Default
)
Now, your combobox will not only have matching schemas in the defaults and the items, but it will now allow you to Update the underlying record with the .SelectedItems property of the combobox as it will also match the required record type for a Choice column.
@RandyHayes , thank you very much for this! I updated the Items and DefaultSelectedItems as you suggested,and DefaultSelectedItems shows this error: "The function If has some invalid arguments".
the error message is gone when I remove Parent.Default from the formula and leave as this:
DefaultSelectedItems = If(varFormMode = FormMode.New,
RenameColumns(
Distinct(
Filter(
MTDemoSPList2,
Books = cmb_Demo1.Selected.Result
),
Library
),
"Result",
"Value"
)
)
Is it possible to fix such issue?
If I use ThisItem.'Library' instead of Parent.Default, everything seems to work..
User | Count |
---|---|
263 | |
110 | |
92 | |
55 | |
41 |