Hello,
I have a combo box set up in my app that references a list of my customers from Business Central, this field is called company name and the source is called customers. I want to use the selected value from that combo box to populate a label with the corresponding company number (field called number) for the user's selection.
What I've tried is as follows:
If(IsEmpty(ComboBox3.SelectedItems), Blank(), LookUp(customers, ComboBox3.SelectedItems= customers.displayName, number))
If no selection has been made yet (i.e ComboBox3 is empty) then I want the label to show blank,
else I want the label value to be looked up in my customers table where the customer.displayname (company name) is equal to the value in the combo box and for it to return the company number as the label's value.
I keep hitting the same error under the "=" in the condition argument using the syntax above saying there is an invalid argument type for the function. What am I doing wrong?
Hi @accorti
I think the syntax you need would look along the lines of this:
If(IsEmpty(ComboBox3.SelectedItems),
Blank(),
LookUp(customers, ComboBox3.Selected.Value = customers.displayName, number)
)
If ComboBox3.Selected.Value isn't valid, you can type the line beneath:
ComboBox3.Selected.
The intellisense in the formula bar should show you the list of valid property names.
@timl Thats a good thought. However I am still receiving he same error with "=". For your reference, intellisense was not providing the .Value property, but only provided .displayname which is the field in Business Central that provides customer name.
I am curious though, with your method why would we use .Selected rather than .SelectedItems? Is the difference between them just allowing for a single value vs a table of values?
Thanks
Hi @accorti
Just to confirm, this still gives you the same error?
If(IsEmpty(ComboBox3.SelectedItems),
Blank(),
LookUp(customers, ComboBox3.Selected.displayName = customers.displayName, number)
)
Yes, you're correct that .Selected returns the currently selected item in the Combobox. A Combobox can have multiple selected items, and this is what SelectedItems would return.
You might also want to try this to see if it makes a difference...
If(IsEmpty(ComboBox3.SelectedItems),
Blank(),
LookUp(customers, ComboBox3.Selected.displayName = displayName, number)
)
Hi @accorti ,
Could you please share a bit more about the formula you typed within the Items property of the ComboBox?
Do you enable single value option or Multiple options within the ComboBox? Do you set the displayName column from your customers data source as display value within the ComboBox?
I assume that you enable single value option within the ComboBox, and set the displayName column as display value, is it true?
Based on the formula you provided, I think there is something wrong with it. I have made a test on my side, please consider take a try with the following workaround:
Set the Items property of the ComboBox3 to following:
customers
set the displayName column as display value within the ComboBox3.
Set the Text property of the Label to following:
If(
IsBlank(ComboBox3.Selected.Value),
Blank(),
LookUp(customers, displayName = ComboBox3.Selected.displayName, number)
)
In addition, please also consider take a try with the following workaround:
Set the Items property of the ComboBox3 to following:
Distinct(customers, displayName)
set the Result property as display value within the ComboBox3.
Set the Text property of the Label to following:
If(
IsBlank(ComboBox3.Selected.Result),
Blank(),
LookUp(customers, displayName = ComboBox3.Selected.Result, number)
)
Please consider take a try with above solution, check if the issue is solved.
Best regards,
Some Questions I have on your response:
(quotes are just for the context of the post, not actually used in the formulas)
1) If I set the items property on the ComboBox to just "customers" then it does not show anything because it is a table of values. I have to specify the column I need displayed. i.e. "customers.displayName"
2) I do not see a "Result" Property for the combobox, can you specify what you might mean by this?
Additionally, with your last solution
If( IsBlank(ComboBox3.Selected.Result), Blank(), LookUp(customers, displayName = ComboBox3.Selected.Result, number) )
I received the following error: "The requested operation is invalid. server response: Logical Operator 'equal' is not allowed. To Allow it, set the 'AllowedLogicalOperators' property on EnableQueryAttribute or queryvalidationsettings."
Hi @accorti ,
Could you please share a bit more about the displayName column in your customers data source? Is it a Text type column?
Could you please share a screenshot about the issue with the formula in your app?
For your first question, when you set the Items property of the ComboBox to "customers", you need to set the Primary text field and SearchField property to proper column, e.g. displayName.
If you set the Items property of the ComboBox to the Distinct(...) formula I mentioned above, you need also to set the Primary text field and SearchField property to Result.
For your second question, based on the issue that you mentioned, I have made a test on my side, and don't have the issue that you mentioned. Please check if you have type the above LookUp formula within the Text property of the Label control.
You could consider set the Items property of the ComboBox to following:
customers
set the Primary text field and SearchField property to displayName.
Set the Text property of the Label to following formula:
If(
IsBlank(ComboBox3.Selected.displayName),
Blank(),
LookUp(customers, displayName = ComboBox3.Selected.displayName, number)
)
Note: Do not type customers.displayName within your LookUp formula, the result the customers.displayName formula returns is a Table value. If you want to compare the displayName column in your customers data source with the selected value in your ComboBox, please consider specify the displayName column in the LookUp formula directly.
Best regards,
@v-xida-msft Appreciate the time you put into this response. DisplayName is a text field that should display a list of customer names (company name). I would like to use a combobox populated with the customer name to look up their corresponding customer ID number in the label control.
1) The only option I'm getting for the combobox primary text and search field is "result" (see screenshot below).
2) I've tried the formula you specified for the label text property. I'm receiving a few errors. See below.
If you were able to reproduce this solution with no issues, it would appear that I have some property or formula set incorrectly. I'll keep checking to see if there is something incorrect that stands out. Thanks
Hi @accorti ,
Based on the formula that you mentioned, I think there is something wrong with it. If you could only get "Result" option from the Primary text property and SearchField property in your ComboBox, on your side, you need to modify your formula as below:
Set the Text property of the Label to following formula:
If(
IsBlank(ComboBox3.Selected.Result),
Blank(),
LookUp(customers, displayName = ComboBox3.Selected.Result, number)
)
Note: Please type ComboBox3.Selected.Result rather than ComboBox3.Selected.displayName
Best regards,
User | Count |
---|---|
125 | |
87 | |
86 | |
75 | |
69 |
User | Count |
---|---|
215 | |
181 | |
139 | |
97 | |
83 |