Solved

Custom string list value should be set to my grid field

  • 28 June 2023
  • 8 replies
  • 113 views

Userlevel 3
Badge

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?

icon

Best answer by davidnavasardyan09 28 June 2023, 17:29

View original

8 replies

Userlevel 7
Badge +17

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.
Userlevel 3
Badge

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.? 

Userlevel 7
Badge +17

@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”.

Userlevel 3
Badge

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?

Userlevel 7
Badge +17

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

Userlevel 3
Badge

@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?

Userlevel 7
Badge +17

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

Userlevel 5
Badge +1

@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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved