Skip to main content
Answer

Transferring Value from Non-Database Field to Custom Field in Employee Payroll Settings

  • September 29, 2025
  • 3 replies
  • 75 views

Sagar Greytrix
Captain II
Forum|alt.badge.img+3

Hi Team,


In the Employee Payroll Settings screen, there is a 'Tax Setting' tab that has a 'Name' field. This field does not exist in the database.

I added a custom field and tried to store the value from the 'Name' field into my custom field, but I'm not getting the expected result.

Could you please assist me with how to transfer the value from the non-existing field to the custom field?

 

 

 

  public class PREmployeePayrollSettingsMaint_Extension : PXGraphExtension<PX.Objects.PR.PREmployeePayrollSettingsMaint>
  {
      #region Event Handlers
      protected void _(Events.RowPersisting<PREmployeeAttribute> e)
      {
          if (e.Row == null) return;

          var row = e.Row;
          var rowExt = row.GetExtension<PREmployeeAttributeExt>();

          // Copy Description field value to your custom field
          e.Cache.SetValue<PREmployeeAttributeExt.usrName>(row, row.Description );
      }


      #endregion
  }

Best answer by darylbowman

Something like this is what I had in mind:

public delegate void PersistDelegate();

[PXOverride]
public virtual void Persist(PersistDelegate baseMethod)
{
// Update UsrDescription for inserted records
foreach (PREmployeeAttribute attr in Base.EmployeeAttributes.Select())
{
var ext = PXCache<PREmployeeAttribute>.GetExtension<PREmployeeAttributeExt>(attr);
if (ext is object)
ext.UsrDescription = attr.Description;
}

// Call base Persist method
baseMethod();
}

 

If that doesn’t work, I did locate where the value comes from, but I haven’t digested why what you’re trying isn't working. It comes from a dynamically added FieldSelecting event handler in PRAttributeListSelect.cs

public PRAttributeSelectBase(PXGraph graph)
{
_Graph = graph;
_Graph.FieldSelecting.AddHandler(typeof(TEntity), "Description", DescriptionFieldSelecting);
}
protected virtual void DescriptionFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
TEntity row = e.Row as TEntity;
if (string.IsNullOrEmpty(row?.SettingName))
{
return;
}

ISettingDefinition settingDefinition = GetSettingDefinition(row.SettingName);
if (settingDefinition != null)
{
e.ReturnValue = settingDefinition.Description;
}
}

 

3 replies

darylbowman
Captain II
Forum|alt.badge.img+15
  • September 29, 2025

Are you sure the event has fired? Did you make a change to the attribute that needed to be persisted?

I would instead override the Persist method of the graph and loop through each attribute before the base Persist is executed.


Sagar Greytrix
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • September 30, 2025

@darylbowman Thanks for your response. I tried using multiple events and overrides, but sometimes the screen crashes, and other times the data does not get passed. Also, when I try with another field, the data passes successfully into my custom field, but for the field that displays "Name" (the description field), it is not working.

 

 public class PREmployeePayrollSettingsMaint_Extension : PXGraphExtension<PX.Objects.PR.PREmployeePayrollSettingsMaint>
 {
     #region Event Handlers
     public delegate void _Delegate(RowPersisting<PREmployeeAttribute> e);
     [PXOverride]
     public void _(RowPersisting<PREmployeeAttribute> e, _Delegate baseMethod)
     {
         // Update UsrName using Base.EmployeeAttributes view
         foreach (PREmployeeAttribute attr in Base.EmployeeAttributes.Cache.Inserted)
         {
             var ext = PXCache<PREmployeeAttribute>.GetExtension<PREmployeeAttributeExt>(attr);
             if (ext != null)
             {
                 ext.UsrDescription = attr.Description;
             }
         }

         foreach (PREmployeeAttribute attr in Base.EmployeeAttributes.Cache.Updated)
         {
             var ext = PXCache<PREmployeeAttribute>.GetExtension<PREmployeeAttributeExt>(attr);
             
                 ext.UsrDescription = attr.Description;
             
         }

         baseMethod(e);
     }

     #region Override Persist

     public delegate void PersistDelegate();

     [PXOverride]
     public virtual void Persist(PersistDelegate baseMethod)
     {
         // Update UsrDescription for inserted records
         foreach (PREmployeeAttribute attr in Base.EmployeeAttributes.Cache.Inserted)
         {
             var ext = PXCache<PREmployeeAttribute>.GetExtension<PREmployeeAttributeExt>(attr);
             if (ext != null)
             {
                 ext.UsrDescription = attr.Description;
             }
         }

         // Update UsrDescription for updated records
         foreach (PREmployeeAttribute attr in Base.EmployeeAttributes.Cache.Updated)
         {
             var ext = PXCache<PREmployeeAttribute>.GetExtension<PREmployeeAttributeExt>(attr);
           
             
              ext.UsrDescription = attr.Description;
             
         }

         // Call base Persist method
         baseMethod();
     }

     #endregion

     protected virtual void _(Events.FieldSelecting<PREmployeeAttribute, PREmployeeAttributeExt.usrDescription> e)
     {
         if (e.Row == null) return;

         // Show Description in UsrDescription field
         e.ReturnValue = e.Row.Description;
     }
 }


darylbowman
Captain II
Forum|alt.badge.img+15
  • Answer
  • September 30, 2025

Something like this is what I had in mind:

public delegate void PersistDelegate();

[PXOverride]
public virtual void Persist(PersistDelegate baseMethod)
{
// Update UsrDescription for inserted records
foreach (PREmployeeAttribute attr in Base.EmployeeAttributes.Select())
{
var ext = PXCache<PREmployeeAttribute>.GetExtension<PREmployeeAttributeExt>(attr);
if (ext is object)
ext.UsrDescription = attr.Description;
}

// Call base Persist method
baseMethod();
}

 

If that doesn’t work, I did locate where the value comes from, but I haven’t digested why what you’re trying isn't working. It comes from a dynamically added FieldSelecting event handler in PRAttributeListSelect.cs

public PRAttributeSelectBase(PXGraph graph)
{
_Graph = graph;
_Graph.FieldSelecting.AddHandler(typeof(TEntity), "Description", DescriptionFieldSelecting);
}
protected virtual void DescriptionFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
TEntity row = e.Row as TEntity;
if (string.IsNullOrEmpty(row?.SettingName))
{
return;
}

ISettingDefinition settingDefinition = GetSettingDefinition(row.SettingName);
if (settingDefinition != null)
{
e.ReturnValue = settingDefinition.Description;
}
}