Parse SubAccount to get individual segments

Joseph Caruana

I would like to access the individual segments of a subaccount programmatically. Assuming I have a particular sub account set as ABC-123, I would like to be able to access ABC and 123 separately in code so that I can implement a particular business requirement.

I know that SubAccounts are saved in the Sub table as one string example ABC123. The sub account fields which link to this table would then link based on the ID (integer - PK of the Sub table). I can of course read from this table and then split accordingly (by taking the first 3 characters and the second 3 characters). However, I would like this to be dynamic so that the customization will work for different clients and clients may have different lengths for the segment. Therefore I cannot hard-code the value 3. I can make use of the SegmentValues table to retrieve the lengths of each Segment accordingly.

However, since Acumatica is already somehow carrying out this parsing (example in the UI), is there an API where Acumatica handles this logic and can provide the Sub-account as an array of strings. I tried to look into the SubAccountAttribute, PXDimensionSelectorAttribute, and SubAccountProvider but could not find anything which delivers this functionality.

Does Acumatica provide a way to split the sub-account into an array of strings or should I do this manually by identifying lengths from the Segment Values?

Hugues Beauséjour

I believe some of the logic used to separate the segment are in the protected Definition class. The separated segments are in the Dimensions collections of the Definition class. You can access it in attributes that derive from PXDimensionAttribute class but since Definition class is protected you can't access it in a graph because PXGraph/PXGraphExtension don't derive from it.

Not much can be extracted from Dimension because most properties are protected: enter image description here You can roll your own by reading the segments of the segmented key: enter image description here

Here is an example that write the segment values of the transactions subaccount in the trace for the Invoices and Memos screen:

using PX.Data;
using PX.Objects.AR;
using PX.Objects.CS;
using PX.Objects.GL;

namespace PX.Objects.SO
{
  public class ARInvoiceEntry_Extension : PXGraphExtension<ARInvoiceEntry>
  {
      public void ARTran_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
      {
          ARTran tran = e.Row as ARTran;

          if (tran != null && tran.SubID.HasValue)
          {
                Sub sub = SubAccountAttribute.GetSubaccount(Base, tran.SubID.Value);

                if (sub != null && sub.SubCD != null)
                {
                    short segmentStartIndex = 0;

                    foreach (Segment segment in PXSelect<Segment,
                                                Where<Segment.dimensionID, Equal<Required<Segment.dimensionID>>>,
                                                OrderBy<Asc<Segment.segmentID>>>.Select(Base, "SUBACCOUNT"))
                    {
                        if (segment.SegmentID.HasValue && segment.Length.HasValue)
                        {
                            PXTrace.WriteInformation(string.Format("Segment {0}: {1}",
                                                                   segment.SegmentID,
                                                                   sub.SubCD.Substring(segmentStartIndex, segment.Length.Value)));

                            segmentStartIndex += segment.Length.Value;
                        }
                    }
                }
          }
      }
  }
}

Trace results: enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related