0

In Acumatica I can create a dropdown list field having constant number of values using this approach.

I put my custom attribute on a field.

    #region FieldLocation
    public abstract class fieldLocation : BqlString.Field<fieldLocation> { }
    [PXDBString(5, IsUnicode = true)]
    [PXUIField(DisplayName = "Field Location")]
    [BZMagentoPaymentMethodFieldLocationTypes.BZList] //Dropdown
    
    public string FieldLocation { get; set; }
    #endregion

Custom attribute is something like this.

 public class BZMagentoPaymentMethodFieldLocationTypes
{
    public const string BillingAddress = "BA";
    public const string Payment = "PYMT";
    public const string ExtensionAttributes = "EXTAT";

    public class UI
    {
        public const string BillingAddress = "BillingAddress";
        public const string Payment = "Payment";
        public const string ExtensionAttributes = "Extension Attributes";
    }

    public class BZListAttribute : PXStringListAttribute
    {
        public BZListAttribute() : base(new Tuple<string, string>[]
            {
            Pair(BillingAddress, UI.BillingAddress),
            Pair(Payment, UI.Payment),
            Pair(ExtensionAttributes, UI.ExtensionAttributes)
            })
        { }
    }
}

The result is this.

Values of FieldLocation field

But I DO NOT want constant number of values in dropdown list. I want to take values, for example, from array or JSON. I want something called dynamic dropdown list.

After reading this Stackoverflow discussion I found some tips but I am far from the solution.

I have changed the attribute on field.

    #region FieldLocation
    public abstract class fieldLocation : BqlString.Field<fieldLocation> { }
    [PXDBString(5, IsUnicode = true)]
    [PXUIField(DisplayName = "Field Location")]
    [ConfigurationKeyAttribute("Word", "Text")]
  
    public string FieldLocation { get; set; }
    #endregion

And I have corresponding custom attribute.

 class ConfigurationKeyAttribute : PXStringListAttribute
{
    private string _key;
    private string _value;

    public ConfigurationKeyAttribute(string key, string value) : base(new Tuple<string, string>[]
    {
        Pair(key, value)

    })
    { }       
}

My question is: What can I do to assign a value to an attribute? If I know how to assign a value, then I can assign value taken from JSON request.

vachmir
  • 21
  • 1
  • 1
  • 4

1 Answers1

0

Call PXStringListAttribute.SetList method in the context of RowSelected event handler on the primary DAC of the screen.

protected virtual void PrimaryDAC_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
    Dictionary<string, string> listItems = new Dictionary<string, string>()
    {
        { "key1" , "Value 1" }
        { "key2" , "Value 2" }
        { "key3" , "Value 3" }
    };

    PXStringListAttribute.SetList<DAC.fieldLocation>(sender, dacObject,
                                                     listItems.Keys.ToArray(),
                                                     listItems.Values.ToArray());
}

If you don't need constant values at all you can declare an empty list with PXStringList attribute:

[PXStringList]
[PXStringList(new string[] { null }, new string[] { "" )]
Hugues Beauséjour
  • 8,067
  • 1
  • 9
  • 22
  • Thank You for Your solution. I will change the argument list of SetValue Method to get elements from JSON Model classes using reflection. – vachmir Nov 30 '22 at 10:06
  • You can also use FieldSelecting event and set ReturnState property in your custom attribute inheriting from PXStringListAttribute to achieve similar results. – Hugues Beauséjour Nov 30 '22 at 14:39