Skip to main content
Solved

Custom string list value should be set to my grid field


Forum|alt.badge.img

Hi,

There is a requirement to add custom string list field called Usrdiscountcode in SOLine DAC. I have defined the string list like below.

[PXDBString(1000)]

[PXStringList(new string[]
 
{"A", "B", "C", "D","E","F","G", }, new string[]
{"SPRING",
 "HARVEST",
"XPT",
"TESTTIRE",
"SPECIAL",
"REBATE",
"DISCOUNT"
 })]

[PXUIField(DisplayName="New Discount Code")]

now I need to set the value (ex: SPRING) to a grid level field of the customized screen. For that, I defined an event in the graph extension like this.

using System;
using PX.Objects;
using PX.Data;
using PX.Objects.SO;

namespace GRIProformaInvoice
{
  public class APProformaEntry_Extension : PXGraphExtension<GRIProformaInvoice.APProformaEntry>
  {
    #region Event Handlers

    public PXSelect<SOLine> soview;
    protected void APProformaItemList_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
    {

      var row = (APProformaItemList)e.Row;
      foreach (PXResult<SOLine> result1 in soview.Select())
      {
           SOLine line = result1;
           if(line.OrderNbr==row.Ponbr && line.LineNbr==row.POLineNbr){

                 SOLineExt lines = PXCache<SOLine>.GetExtension<SOLineExt>(line);
                 row.SODiscountCode = lines.Usrdiscountcoden2;

           }
      }    
    }

    #endregion
  }
}

But this time I’m getting the key (ex:”A”) instead of its value of the string list. No idea about what’s missing in this code. Can someone provide me a solution for this to avoid this issue please?

Best answer by davidnavasardyan

@oshadarodrigo64 

The issue you're facing is that the string list you've created in the DAC is an association between keys and values. In your case, "A", "B", "C", etc. are the keys, while "SPRING", "HARVEST", "XPT", etc. are the values. When you try to access the Usrdiscountcoden2 field in your event handler, you're getting the key ("A") instead of its associated value ("SPRING").

You can solve this issue by creating a method in your graph extension that translates the keys into their corresponding values. Here's an example:

 

public class SOLineExt : PXCacheExtension<SOLine>
{
    //...
    public abstract class usrdiscountcoden2 : PX.Data.BQL.BqlString.Field<usrdiscountcoden2> { }

    [PXDBString(1)]
    [PXStringList(new string[]
    {"A", "B", "C", "D","E","F","G", }, new string[]
    {"SPRING",
     "HARVEST",
    "XPT",
    "TESTTIRE",
    "SPECIAL",
    "REBATE",
    "DISCOUNT"
    })]
    [PXUIField(DisplayName="New Discount Code")]
    public virtual string Usrdiscountcoden2 { get; set; }

    //...
}

public class APProformaEntry_Extension : PXGraphExtension<GRIProformaInvoice.APProformaEntry>
{
    //...

    protected void APProformaItemList_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
    {
        //...

        row.SODiscountCode = GetStringValueFromKey(lines.Usrdiscountcoden2);

        //...
    }

    private string GetStringValueFromKey(string key)
    {
        switch(key)
        {
            case "A":
                return "SPRING";
            case "B":
                return "HARVEST";
            case "C":
                return "XPT";
            case "D":
                return "TESTTIRE";
            case "E":
                return "SPECIAL";
            case "F":
                return "REBATE";
            case "G":
                return "DISCOUNT";
            default:
                return null;
        }
    }
    //...
}

This GetStringValueFromKey method will take the key as an input and return the corresponding value. Thus, it solves the issue of getting the key instead of the value. Be aware that it's essential to keep the GetStringValueFromKey method updated if you modify the list in the DAC.

View original
Did this topic help you find an answer to your question?

8 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3411 replies
  • June 28, 2023

Hi @oshadarodrigo64 Can you please let us know for which DAC field you added this STRING LIST?

There are a few mistakes that I have seen in the above code.

  1. STRING List DAC size should 1 and IsFixed = β€œtrue” [PXDBString(1, IsFixed =”true”)]
  2. public PXSelect<SOLine> soview-- > This View is wrong because you are selecting all the Sales Order Lines from SOLine table, which leads to the performance issue.

Forum|alt.badge.img

Hi @Naveen Boga ,

the string list is added to below custom DAC filed in SOline.

I’m not aware about the first point that you mentioned about size of the string list DAC. can’t I define like above. and also how can I change the view into correct one.? 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3411 replies
  • June 28, 2023

@oshadarodrigo64  Thanks for the response.

Have you added the same STRING LIST for the APProformaItemList β†’ SODiscountCOde field as well?

If yes, system will automatically populate the SPRING value, when you assign the β€œA”.


Forum|alt.badge.img

Hi @Naveen Boga 

actually I defined the APProformaItemList.SODicountCode field as only a string field. it’s not a string list field. will that be the issue then?


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3411 replies
  • June 28, 2023

@oshadarodrigo64  Yes, that is the issue. Please make it as STRING LIST and verify.


Forum|alt.badge.img

@Naveen Boga ,

If we need set this kind of string list value, we need to have same set of values defined both in two fields? is that true? Now actually I have set these string list values in soline for testing my development. I gonna publish it to another test server, so in that server, Usrdiiscountcode field can have different string values,

so to assign correct value, same string values should be defined in my SODiscountCode DAC as well?


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3411 replies
  • June 28, 2023

@oshadarodrigo64  Yes, we need to have same set of values.


davidnavasardyan
Jr Varsity I
Forum|alt.badge.img+2

@oshadarodrigo64 

The issue you're facing is that the string list you've created in the DAC is an association between keys and values. In your case, "A", "B", "C", etc. are the keys, while "SPRING", "HARVEST", "XPT", etc. are the values. When you try to access the Usrdiscountcoden2 field in your event handler, you're getting the key ("A") instead of its associated value ("SPRING").

You can solve this issue by creating a method in your graph extension that translates the keys into their corresponding values. Here's an example:

 

public class SOLineExt : PXCacheExtension<SOLine>
{
    //...
    public abstract class usrdiscountcoden2 : PX.Data.BQL.BqlString.Field<usrdiscountcoden2> { }

    [PXDBString(1)]
    [PXStringList(new string[]
    {"A", "B", "C", "D","E","F","G", }, new string[]
    {"SPRING",
     "HARVEST",
    "XPT",
    "TESTTIRE",
    "SPECIAL",
    "REBATE",
    "DISCOUNT"
    })]
    [PXUIField(DisplayName="New Discount Code")]
    public virtual string Usrdiscountcoden2 { get; set; }

    //...
}

public class APProformaEntry_Extension : PXGraphExtension<GRIProformaInvoice.APProformaEntry>
{
    //...

    protected void APProformaItemList_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
    {
        //...

        row.SODiscountCode = GetStringValueFromKey(lines.Usrdiscountcoden2);

        //...
    }

    private string GetStringValueFromKey(string key)
    {
        switch(key)
        {
            case "A":
                return "SPRING";
            case "B":
                return "HARVEST";
            case "C":
                return "XPT";
            case "D":
                return "TESTTIRE";
            case "E":
                return "SPECIAL";
            case "F":
                return "REBATE";
            case "G":
                return "DISCOUNT";
            default:
                return null;
        }
    }
    //...
}

This GetStringValueFromKey method will take the key as an input and return the corresponding value. Thus, it solves the issue of getting the key instead of the value. Be aware that it's essential to keep the GetStringValueFromKey method updated if you modify the list in the DAC.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings