Hi All,
Today I want to discuss with you one short topic – how to implement Combo box with multiple options for select.
As an example I want to use scenario when we need to have a department associated with each particular customer. We have fixed and predefined number of departments so we do not want to configure them. Plus each customer can be associated with multiple departments, so we need to have a multiple options simultaneously.
Based on provided requirements, we can find that Combo Box (Drop Down control) is the best option here.
To do this I will use Acumatica customization engine. Lets go there and do it step by step:
- Go to Customization Projects and create new Project (You also can open existing one)
- Open Customization Browser
- Add screen to customization (In my example it is Customers)
- Open panel where you want to add new field (In my case it is Financial settings near to Customer Class field)
- Select a field and use “Create New Field” command to create a new field
- Provide settings for new field. It should be text field with some length bigger than total length of all values + number of values. This is because Acumatica will store values in database as a combined string – like “Value1,Value2,Value5”. Make sure that your field can store all possible values.
- Than you need to correct attributes, so lets go to Data Access classes and select you class and field.
- Attribute definition – [PXStringList(new string[] { “D”, “C”, “T”, “I” }, new string[] { “Development”, “Consulting”, “Training”, “Implementation” }, MultiSelect = true)] – Please note that there is one additional parameter “MultiSelect = true” that advises Acumatica to store multiple values in this field.
- Validate and publish this customization project. It is required to create a database field and all required support classes. Only after publishing you can continue with creating a field.
- Use “Create Controls” button to create a field. Use drag and drop to adjust field position. Please make sure that your field had type “ComboBox”.
- Set MultiSelect property to True on user interface control. This will set correct behavior for user interface.
- Publish customization once again.
- Done. Do not forget to test it.
This will allow you to have multiple values at once. All values will be in the same DAC field. If you need you can use String.Split(…) to separate each selected field.
In the database you can see how Acumatica stores it.
Have a nice Customization!
I wanted make the Mutiselect Field to Mandatory,on save it is validating and throwing the exception but the Manadatory symbol is not showing in the UI
Here is the Code
[PXDBString(250, IsUnicode = true)]
[PXUIField(DisplayName = “Mapped Warehoueses”,Required =true)]
[KNFNWarehousePrefetch()]
[PXDefault()]
public virtual string MappedWarehoueses { get; set; }
public abstract class mappedWarehoueses : IBqlField { }
Aspx:
There may be several reasons for that, hard to say without code checking.
I recommend you to check CacheAttached handles, Extensions and Events. It is possible that logic is overwritten in some of them.
If that does not help you can create a FieldSelecting event and check what is returned from there. FieldsState contains what should be passed to the UI.
Cosmin,
Unfortunately that is not something out of the box…
You may need to play around with customization and thow an error on FieldVerifying event if user has changes something that is forbidden.
On you can just return value back instead of error.
Hope it helps.
Hi, can I disabled one of the options?
For exemple: there are checked 3 options but the current user can edit only 3 from them.
Or as a work arround to display all selected options inside text box and the drop list to show only editable options.
My practical case is that the Admin is checking one box and the users can check the others but they can not uncheck the Admin selection.
Dear Sergey.
Thakyou for help me.
Dear Aditya,
It seems that your question is answered here.
http://stackoverflow.com/questions/37249865/acumatica-dynamic-multiselect-dropdown
Dear Sergey,
this is code on PXGraph ,class px graph to retrieve data from the database into the combobox
public class StatusMultiStringListAttribute : PXStringListAttribute
{
public StatusMultiStringListAttribute() : base()
{
PXResultset rslt = PXSelect.Select(new PXGraph());
List values = new List();
List labels = new List();
foreach (PXResult item in rslt)
{
BSMTStatus e = (BSMTStatus)item;
values.Add(e.StatusID);
labels.Add(e.Description);
}
this._AllowedValues = values.ToArray();
this._AllowedLabels = labels.ToArray();
MultiSelect = true;
}
}
and this is code in DAC Combobox multiselect
protected string _Status;
[PXDBString(20, IsFixed =true)]
[PXDefault]
[PXUIField(DisplayName = "Status")]
[StatusStringList]
public virtual string Status
{
get
{
return this._Status;
}
set
{
this._Status = value;
}
}
Dear Aditya,
To be able to help you, i need to review your customization code.
Could you please create an support ticket and provide code snippet?
Acumatica team will review it as soon as possible.
for additional data in combobox based on the table is not static
thanks….
why when I save data to a database derived from multiselect combobox, the stored data is not everything
for example, suppose I store the data of 3 pick in the combobox that is stored in the database is only 2, and if I save 2 data stored only one, please help
thank you
HI Gabriel,
Actually I have over-configured it. Just used to do it many times before 😉
I have checked, multiselect works without setting property on the control, so this step can be excluded.
Why isn't the system syncing the MultiSelect property of the control with the attributes? Is that an oversight or the result of some design limitation?