Skip to main content
Solved

Enter the Warehouses screen and the datafield is filled automatically


protected void INLocation_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
      {

              INLocation row = (INLocation)e.Row;
              INLocationExt rowExt = row.GetExtension<INLocationExt>();

              if (rowExt != null)
              {
                  // Accede a la nueva columna y realiza acciones adicionales
                  decimal? valorNuevaColumna = rowExt.UsrVolumen;
                  decimal? valorNuevaColumna2 = 78;

                  // Verifica si es necesario actualizar el objeto INSite
                  INSite orderInCache = Orders.Current as INSite;

                  if (orderInCache != null)
                  {
                      // Ajusta para actualizar el campo usrSumVolumen
                      Orders.Cache.SetValueExt<INSiteExt.usrSumVolumen>(orderInCache, valorNuevaColumna2);
                      PXTrace.WriteInformation("EMPEZAMOS - Nuevo valor: " + valorNuevaColumna2.ToString());

                      // Persiste el cambio
                      Orders.Cache.Persist(PXDBOperation.Update);

                      // Presiona el botón Save para asegurar que los cambios se reflejen en la interfaz de usuario
                      Orders.Cache.Graph.Actions.PressSave();
                  }
                  else
                  {
                      PXTrace.WriteInformation("orderInCache es nulo");
                  }
              }
              else
              {
                  PXTrace.WriteInformation("rowExt es nulo");
              }


       }

When reviewing the Last Requests, if it brings the requested values but does not insert it in UsrSumVolumen, can you help me solve it?

Best answer by darylbowman

Try this:

protected virtual void _(Events.FieldSelecting<INSite, INSiteExt.usrSumVolumen> e)
{
    INSite row = e.Row;
    if (row is null) return;

    decimal sum = 0m;
    foreach (INLocation location in Base.location.Select())
    {
        var locationExt = row.GetExtension<INLocationExt>();
        sum += locationExt?.UsrVolumen ?? 0m;
    }

    e.ReturnValue = sum;
}

This is assuming that UsrSumVolumen is a non-persisted field. FieldSelecting should NOT be used on a persisted field.

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

3 replies

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

RowSelected is not the correct event for this situation. Without seeing your custom field definition, it's hard to say what you're trying to accomplish. If you're trying to set the value of an unbound field, you should use FieldSelecting for each field to calculate and display the value. If you're trying to default a value that can be modified, use FieldDefaulting.


  • Author
  • Freshman I
  • 1 reply
  • November 29, 2023

The purpose is to add the values of the volume column (image 2) so that the result is added to sumvolume (image 3), this is what appears in the last requests

When we add a new field, if you perform the operation at this moment, assign it the 78 and not the sum, but it only adds it when modifying as shown in the image below

I already tried what you told me about with FieldSelecting and FieldDefaulting. Can you help me, I would appreciate it very much.


darylbowman
Captain II
Forum|alt.badge.img+13
  • 1712 replies
  • Answer
  • November 29, 2023

Try this:

protected virtual void _(Events.FieldSelecting<INSite, INSiteExt.usrSumVolumen> e)
{
    INSite row = e.Row;
    if (row is null) return;

    decimal sum = 0m;
    foreach (INLocation location in Base.location.Select())
    {
        var locationExt = row.GetExtension<INLocationExt>();
        sum += locationExt?.UsrVolumen ?? 0m;
    }

    e.ReturnValue = sum;
}

This is assuming that UsrSumVolumen is a non-persisted field. FieldSelecting should NOT be used on a persisted field.


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