Skip to main content
Solved

ADD A NEW COLUMN FROM AN ANOTHER TABLE : DUNNING LETTER

  • November 25, 2024
  • 6 replies
  • 79 views

Hello everyone!

I’m trying to add a column from the BAccount table to the AR.52.10.00 Prepare Dunning Letter screen in order to provide more information.

I wrote the following code, which publishes without errors. However, when I check the screen, the data doesn’t appear, and I can’t figure out where I might have gone wrong or if I’m approaching this incorrectly:

 

using System;
using System.Collections;
using System.Collections.Generic;
using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Objects.CM;
using PX.Objects.Common.Extensions;
using PX.Objects.GL.FinPeriods;
using PX.Objects;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.CS;

namespace PX.Objects.AR
{
  public class ARDunningLetterMaint_Extension : PXGraphExtension<PX.Objects.AR.ARDunningLetterMaint>
  {
  protected void  ARDunningLetterList_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
    {
        var row = (ARDunningLetterProcess.ARDunningLetterList)e.Row;
        if (row == null || row.BAccountID == null) return;

        BAccount account = PXSelect< BAccount,
            Where< BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>
            .Select(Base, row.BAccountID);

        if (account != null)
        {
            var accountExt = PXCache<BAccount>.GetExtension<BAccountExt>(account);
            var rowExt = cache.GetExtension<ARDunningLetterListExt>(row);

         if (rowExt != null && accountExt != null)
        {
            rowExt.UsrSectGeo = accountExt?.UsrSecteurGeo;
            cache.Update(row); // Force la mise à jour
        }
        }
    }
  }
}

 

The process:

  1. I created a new field.
  2. I added it as an extension to the DAC (ARDunningLetterList)
  3. I created an extension for ARDunningLetterMaint

 

Thanks in advance for your help ! 

Best answer by noorula77

Hi ​@MargauxCella ,

If there is a mismatch between the keys ("CESE", "IDF", etc.) and the labels ("CENTRE EST/SUD-EST", "ILE DE FRANCE", etc.), selections may not work properly.
 
 

protected void ARDunningLetterList_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
    var row = (ARDunningLetterProcess.ARDunningLetterList)e.Row;
    if (row == null)
        return;

    // Example: Dynamic adjustment of list values (optional)
    PXStringListAttribute.SetList<ARDunningLetterListExt.usrSectGeo>(
        cache, 
        row, 
        new string[] { "CESE", "IDF", "NNE", "OUE" },
        new string[] { "CENTRE EST/SUD-EST", "ILE DE FRANCE", "NORD/NORD-EST", "OUEST" }
    );
}
 

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

6 replies

Forum|alt.badge.img+1
  • Jr Varsity I
  • 62 replies
  • November 25, 2024

Hi ​@MargauxCella

The RowPersisting event is primarily used for validation or last-moment updates before persisting data. This may not trigger the UI to display the updated data. Instead, use FieldSelectingRowSelected or RowUpdated events to ensure the calculated field is populated for display during interaction with the grid. 
 

protected void ARDunningLetterList_UsrSectGeo_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)

{

    // Ensure we have a valid row

    var row = (ARDunningLetterProcess.ARDunningLetterList)e.Row;

    if (row == null || row.BAccountID == null)

        return;

 

    // Fetch the related BAccount

    BAccount account = PXSelect<BAccount,

        Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>

        .Select(Base, row.BAccountID);

 

    if (account != null)

    {

        // Get the custom extension fields

        var accountExt = PXCache<BAccount>.GetExtension<BAccountExt>(account);

 

        // Provide the value for the UsrSectGeo field dynamically

        if (accountExt != null)

        {

            e.ReturnValue = accountExt.UsrSecteurGeo;

        }

    }

}


  • Author
  • Freshman I
  • 5 replies
  • November 26, 2024

Hi ​@noorula77 ! 

Thank you so much for your response and explanations! I really appreciate it and will look into learning more about the Event !

Unfortunately, I tried your code, but my field “Geographical Sector” remains empty, even though there is a value associated with the customer code

 


darylbowman
Captain II
Forum|alt.badge.img+13

@MargauxCella - Your code appears to be in an extension of the ARDunningLetterMaint graph, but the screen in your screenshot is the ARDunningLetterProcess graph (if I’m not mistaken). That would be a problem.


Forum|alt.badge.img+1
  • Jr Varsity I
  • 62 replies
  • November 26, 2024

Hi ​@MargauxCella,
As mention ​@darylbowman can you write code on ARDunningLetterProcess graph as shown screen shot. I think graph name would be a problem.
 

 


  • Author
  • Freshman I
  • 5 replies
  • December 4, 2024

Hi everyone! Thank you all so much for your help!

After spending some time debugging, I finally discovered my (other) mistake. Now, I can successfully see the value from my other table. 

protected void ARDunningLetterList_UsrSectGeo_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)

    {

    var row = (ARDunningLetterProcess.ARDunningLetterList)e.Row;

    if (row == null || row.BAccountID == null)

        return;

    // Liaison customer

    Customer customer = PXSelect<Customer,

        Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>

        .Select(Base, row.BAccountID);

      if (customer != null)

        {    

            //récupération de l'user-defined-field   

           var customerGraph = PXGraph.CreateInstance<CustomerMaint>();

           var csgeo = (PXStringState)customerGraph.BAccount.Cache.GetValueExt(customer, "AttributeCSGEO");            

            if (csgeo != null)

           {

            e.ReturnValue = csgeo;

            cache.SetValueExt<ARDunningLetterListExt.usrSectGeo>(row,csgeo)                 

           }          

          PXTrace.WriteInformation($"Customer ID: {customer.BAccountID}, Csgeo: {csgeo}");

         }

      }

  public class ARDunningLetterListExt : PXCacheExtension<PX.Objects.AR.ARDunningLetterProcess.ARDunningLetterList>

  {

    #region UsrSECTGEO

    [PXDBString(10)]

    [PXStringList(new string[] {"CESE", "IDF", "NNE", "OUE"}, new string[] {"CENTRE EST/SUD-EST", "ILE DE FRANCE", "NORD/NORD-EST", "OUEST"})]

    [PXUIField(DisplayName="Secteur Géographique")]

  

    public virtual string UsrSectGeo { get; set; }

    public abstract class usrSectGeo : PX.Data.BQL.BqlString.Field<usrSectGeo> { }

    #endregion

  }

 

But now I have another problem. :(
I can’t filter the value. When I select a value from the list, it doesn’t return anything...

Do you have any ideas on how I could fix this?

 


Forum|alt.badge.img+1
  • Jr Varsity I
  • 62 replies
  • Answer
  • December 4, 2024

Hi ​@MargauxCella ,

If there is a mismatch between the keys ("CESE", "IDF", etc.) and the labels ("CENTRE EST/SUD-EST", "ILE DE FRANCE", etc.), selections may not work properly.
 
 

protected void ARDunningLetterList_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
    var row = (ARDunningLetterProcess.ARDunningLetterList)e.Row;
    if (row == null)
        return;

    // Example: Dynamic adjustment of list values (optional)
    PXStringListAttribute.SetList<ARDunningLetterListExt.usrSectGeo>(
        cache, 
        row, 
        new string[] { "CESE", "IDF", "NNE", "OUE" },
        new string[] { "CENTRE EST/SUD-EST", "ILE DE FRANCE", "NORD/NORD-EST", "OUEST" }
    );
}
 


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