Monday, 28 March 2016

Multiselect Combo Box

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:


  1. Go to Customization Projects and create new Project (You also can open existing one)
  2. Open Customization Browser
  3. Add screen to customization (In my example it is Customers)
  4. Open panel where you want to add new field (In my case it is Financial settings near to Customer Class field)
  5. Select a field and use "Create New Field" command to create a new field
  6. 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.
  7. Than you need to correct attributes, so lets go to Data Access classes and select you class and field.
  8. 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.
  9. 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.
  10. 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".
  11. Set MultiSelect property to True on user interface control. This will set correct behavior for user interface.
  12. Publish customization once again.
  13. 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!

10 comments:

Gabriel Michaud said...

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?

Sergey Marenich said...

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.

aditya kharisma harsono said...

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

aditya kharisma harsono said...

for additional data in combobox based on the table is not static
thanks....

Sergey Marenich said...

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.

aditya kharisma harsono said...

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;
}
}



Sergey Marenich said...

Dear Aditya,

It seems that your question is answered here.
http://stackoverflow.com/questions/37249865/acumatica-dynamic-multiselect-dropdown

Aditya Kharisma Harsono said...

Dear Sergey.

Thakyou for help me.

Cosmin said...

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.

Sergey Marenich said...

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.