-->

Acumatica Dynamic MultiSelect Dropdown

2019-07-14 02:19发布

问题:

I have a screen entry to store transaction data, I want to use dynamic with multiselect combobox to select status and status data is taken from the table, but when some of the data status is selected, the amount of stored data does not match that has been selected,

I have tried the following code, but it's doesn't work for me.

 public class StatusMultiStringListAttribute : PXStringListAttribute
{
    public StatusMultiStringListAttribute() : base()
    {
        PXResultset<StatusTable> rslt = PXSelect<StatusTable>.Select(new PXGraph());
        List<string> values = new List<string>();
        List<string> labels = new List<string>();
        foreach (PXResult<StatusTable> item in rslt)
        {
            BSMTStatus e = (StatusTable)item;
            values.Add(e.StatusID);
            labels.Add(e.Description);
        }

        this._AllowedValues = values.ToArray();
        this._AllowedLabels = labels.ToArray();
        MultiSelect = true;
    }
}

is there any other solution, sorry my English is bad, thanks.

回答1:

I noticed your comment on http://asiablog.acumatica.com/2016/03/multiselect-combo-box.html and saw that you posted some additional code. Based on your sample code, I identified two problems:

First of all, the values you're loading from the StatusTable DAC contain trailing spaces which are not trimmed. You haven't provided the declaration of the StatusTable DAC, but it's safe to assume from your screenshot that this field has the IsFixed attribute set to true. With these settings, the system will add white space at the end of your value. To save space in the target field, I would recommend to add a Trim() to the constructor code:

foreach (PXResult<StatusTable> item in rslt)
{
    BSMTStatus e = (StatusTable)item;
    values.Add(e.StatusID.Trim()); //Remove any white-space
    labels.Add(e.Description);
}

Second, the status field where you're storing the selected values is not long enough to accommodate multiple selections. It's currently defined as 20 characters ([PXDBString(20, IsFixed=true)]), and even assuming you remove the whitespace you would still be limited to 4 choices. I suggest you to change it to 255, and to also remove IsFixed=true since it's not needed for this field:

[PXDBString(255)]
[PXDefault]
[PXUIField(DisplayName = "Status")]
[StatusStringList]
public virtual string Status


标签: c# erp acumatica