0
votes

While creating GI for sales order screen I want to display the total number of lines in document details tab. Can anyone suggest a way to start implementing this?

After including the custom field in GI it doesn't populate the column with data.

The code for printing the row count is as below which is also discussed in Adding custom button in acumatica

public void SOOrder_UsrTotalTransactions_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
  {
      e.ReturnValue = GetTotalTransactions(sender);
  }

  // Update values
  public void SOLine_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
  {
      UpdateTotals(sender, e.Row as SOOrder,  true);
  }

  public void SOLine_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
  {
      UpdateTotals(sender, e.Row as SOOrder,  true);
}

  public void SOLine_OrderQty_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
  {
      UpdateTotals(sender, e.Row as SOOrder, false);
  }

  public void UpdateTotals(PXCache sender, SOOrder soOrder, bool isUpdateTranCount)
  {
      // Get SOOrder DAC extension
      if (soOrder != null)
      {
          SOOrderExt soOrderExt = sender.GetExtension<SOOrderExt>(soOrder);

          if (soOrderExt != null)
          {             
               if (isUpdateTranCount)
               {

                   sender.SetValueExt<SOOrderExt.usrTotalTransactions>(soOrder, GetTotalTransactions(sender));

               } 
          }
      }
  }



  public int? GetTotalTransactions(PXCache sender)
  {
      return Base.Transactions.Select().Count();
  }
 }
}

the DAC code is: [PXDBInt] [PXUIField(DisplayName="Total Lines", Enabled = false)]

1
The reason it doesn't work is the GI just uses the DACs and if you are setting an unbound field in another graph or within the dac referencing another graph it will not work in the GI which is its own graph. Maybe the use of some type of PXProjection or PXDBCalc field. Alternative would be to simply store the value into the field and save to the DB in the sale order graph. - Brendan
Can you please explain how can I store the value in the database? The custom i created does show the value but it doesn't saves in the DB...it shows NULL - Naina
you need to find the right trigger... maybe persist override would be easiest and before calling base persist check the row count (watch out for deleting still being included in the count) and update your order UsrRowCount value. - Brendan
can you include the code you have to help answer the question? - include it in the question - not a comment if you can please - Brendan
I have edited my question with the code... - Naina

1 Answers

0
votes

If you are trying to set the value I would try a simplified version of your example like this...

namespace PX.Objects.SO
{
    public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
    {
        public void SOLine_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
        {
            UpdateTotals(sender, e.Row as SOOrder);
        }

        public void SOLine_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            UpdateTotals(sender, e.Row as SOOrder);
        }

        public void UpdateTotals(PXCache sender, SOOrder soOrder)
        {
            if (soOrder != null)
            {
                SOOrderExt soOrderExt = sender.GetExtension<SOOrderExt>(soOrder);

                if (soOrderExt != null)
                {
                    sender.SetValueExt<SOOrderExt.usrRowCount>(soOrder, GetRowCount());
                }
            }
        }

        public int GetRowCount()
        {
            return Base.Transactions?.Select().Count() ?? 0;
        }
    }
}

You would use FieldSelecting to set unbound field values. Because your field is bound you do not want to call fieldselecting for your example.