Question

How to see all the the records regardless of the company or branch that I am logged in?

  • 22 December 2022
  • 3 replies
  • 154 views

Hello,

I have a custom DAC called Unidad and I need to see all the records regardless of the company or branch that I am logged in,

I tried to do this but it did not work: https://stackoverflow.com/questions/58980178/how-do-i-return-data-for-other-branches-for-a-user-with-access-to-only-one-branc

This is my custom DAC:

using System;

using PX.Data;

using PX.Objects.AP;

using PX.Objects.GL;

using PX.CS;

using PX.Objects.CR;

using PX.Objects.AR;

using HgDevTraficoLocal;

namespace HgDevSeguridad

{

  [Serializable]

  [PXCacheName("Unidad")]

  public class Unidad : IBqlTable

  {

    #region BranchID

    [Branch()]

    [PXUIField(DisplayName = "Branch ID")]

    public virtual int? BranchID { get; set; }

    public abstract class branchID : PX.Data.BQL.BqlInt.Field<branchID> { }

    #endregion

    #region UnidadID

    [PXDBIdentity()]

    public virtual int? UnidadID { get; set; }

    public abstract class unidadID : PX.Data.BQL.BqlInt.Field<unidadID> { }

    #endregion

    #region UnidadCD

    [PXDBString(255, InputMask = "", IsKey = true, IsUnicode = true)]

    [PXUIField(DisplayName = "Unidad ID")]

    [PXSelector(

      typeof(Search<Unidad.unidadCD>),

      typeof(Unidad.unidadCD),

      typeof(Unidad.description),

      typeof(Unidad.marcaID),

      typeof(Unidad.tipoid),

      typeof(Unidad.estadoID))]

    public virtual string UnidadCD { get; set; }

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

    #endregion

    #region Description

    [PXDBString(255, InputMask = "")]

    [PXUIField(DisplayName = "Description")]

    public virtual string Description { get; set; }

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

    #endregion

    #region Noteid

    [PXNote()]

    public virtual Guid? Noteid { get; set; }

    public abstract class noteid : PX.Data.BQL.BqlGuid.Field<noteid> { }

    #endregion

  }

      

  public class constantTipoTransfer: PX.Data.Constant<string>

  {

    public constantTipoTransfer() : base("TRANSFER") { }

  }

  public class constantTipoPermisionario: PX.Data.Constant<string>

  {

    public constantTipoPermisionario() : base("PERM") { }

  }

}

This is my custom graph:

using System;

using PX.Data;

using HgDevLlantas;

using PEFEMex;

using PEFEMX;

using System.Collections;

namespace HgDevSeguridad

{

  public class UnidadMaint : PXGraph<UnidadMaint, Unidad>

  {

    public PXChangeID<Unidad, Unidad.unidadCD> ChangeID;

    

    public PXSelect<LIUnidadLlantas, Where<LIUnidadLlantas.unidadID, Equal<Current<Unidad.unidadID>>>> UnidadLlantasQuery;

    decimal? KilometrajeSumado = 0;

    

    protected void Unidad_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)

    {

       Unidad row = (Unidad)e.Row;

      

      if (row == null)

      {

          return;

      }

      if (row.Propietario == "Propio")

      {

          GenerarUnidadVehicular();

      }

      

      foreach(LIUnidadLlantas UnidadLlantas in UnidadLlantasQuery.Select())

      {

          this.Clear(PXClearOption.ClearQueriesOnly);

          KilometrajeSumado = 0;

           

          if (UnidadLlantas == null)

          {

              return;

          }    

        

          LICatLlantSerie LlantSerie = PXSelect<LICatLlantSerie,

                                          Where<LICatLlantSerie.inventoryID, Equal<Required<LICatLlantSerie.inventoryID>>,

                                            And<LICatLlantSerie.lotSerialNbr, Equal<Required<LICatLlantSerie.lotSerialNbr>>>>>.Select(this, UnidadLlantas.InventoryID, UnidadLlantas.LotSerialNbr);

          

          if (LlantSerie == null)

          {   

              return;

          }

      

          KilometrajeSumado = LlantSerie.KilometrajeTotal;

        

          //Kilometraje Total Llanta    

          if (LlantSerie.KilometrajeTotal == null)

          {

              LlantSerie.KilometrajeTotal = row.KilometrajeActual;

              this.Clear(PXClearOption.ClearQueriesOnly);

              KilometrajeSumado = 0;

          }

          else

          {

              LlantSerie.KilometrajeTotal = KilometrajeSumado + row.KilometrajeActual;

              this.Clear(PXClearOption.ClearQueriesOnly);

              KilometrajeSumado = 0;

          }

      

          //Consulta para obtener la ultima profundidad

          LICatLlantSerieHisto LlantSerieHisto = PXSelect<LICatLlantSerieHisto,

                                                    Where<LICatLlantSerieHisto.inventoryID, Equal<Required<LICatLlantSerieHisto.inventoryID>>,

                                                      And<LICatLlantSerieHisto.lotSerialNbr, Equal<Required<LICatLlantSerieHisto.lotSerialNbr>>>>,

                                                 OrderBy<Desc<LICatLlantSerieHisto.lineNbr>>>.SelectWindowed(this, 0, 1, UnidadLlantas.InventoryID, UnidadLlantas.LotSerialNbr);

          

          if (LlantSerieHisto == null)

          {

              return;

          }

      

          //Costo por Milimetro

          if (LlantSerieHisto.Profundidad == 0)

          {

              LlantSerie.CostoMilimetro = 0;

          }

          else

          {

              LlantSerie.CostoMilimetro = LlantSerieHisto.Costo / LlantSerieHisto.Profundidad;

          }

      

          //Costo por Kilometro

          if (LlantSerieHisto.Costo == 0)

          {

              LlantSerie.CostoKilometro = 0;

          }

          else

          {

              LlantSerie.CostoKilometro = LlantSerie.KilometrajeTotal / LlantSerieHisto.Costo;

          }

          

          cache = base.Caches[typeof(LICatLlantSerie)];

          cache.Update(LlantSerie);

          cache.Persist(LlantSerie, PXDBOperation.Update);

          cache.Clear();

      }

    }

        

    protected void GenerarUnidadVehicular()

    {

        Unidad unidad = (Unidad)this.UnidadView.Current;

        

        if (unidad == null)

        {

            return;

        }

        PEFEVehicleUnitsMaint graph = PXGraph.CreateInstance<PEFEVehicleUnitsMaint>();

        PEFEVehicleUnits vehicleUnits = (PEFEVehicleUnits)graph.VehicleUnits.Cache.CreateInstance();

        

        PEFEVehicleUnits consultaVehicleUnits = PXSelect<PEFEVehicleUnits, Where<PEFEVehicleUnits.unitCD, Equal<Required<PEFEVehicleUnits.unitCD>>>>.Select(this, unidad.UnidadCD);

        

        int valida = (consultaVehicleUnits == null) ? 0 : 1;

        

        if (valida == 0)

        {

            vehicleUnits.UnitCD = unidad.UnidadCD;

            vehicleUnits.Description = unidad.Description;

        

            PermisoSCT permisoSCT = PXSelect<PermisoSCT, Where<PermisoSCT.permissionID, Equal<Required<PermisoSCT.permissionID>>>>.Select(this, unidad.PermissionID);

            vehicleUnits.PermissionSCT = permisoSCT.PermissionCD;

        

            vehicleUnits.PermitNumber = unidad.PermitNumber;

        

            ConfiguracionVehicular configuracionVehicular = PXSelect<ConfiguracionVehicular, Where<ConfiguracionVehicular.configuracionVehicularID, Equal<Required<ConfiguracionVehicular.configuracionVehicularID>>>>.Select(this, unidad.ConfiguracionVehicularID);

            vehicleUnits.TransportID = configuracionVehicular.ConfiguracionVehicularCD;

        

            vehicleUnits.AutomobileRegistration = unidad.PlacaActual;

            vehicleUnits.ModelYear = unidad.Modelo;

            vehicleUnits.OwnedOrLeased = "02";

        

            ParteVehiculo parteVehiculo = PXSelect<ParteVehiculo, Where<ParteVehiculo.parteVehiculoID, Equal<Required<ParteVehiculo.parteVehiculoID>>>>.Select(this, unidad.ParteVehiculoID);

            vehicleUnits.PartTransport = parteVehiculo.ParteVehiculoCD;

        

            vehicleUnits.CivilLiabilityInsurerID = unidad.AseguradoraID;

            vehicleUnits.CivilLiabilityPolicyNumber = unidad.NumeroPolizaSeguro;

        

            graph.VehicleUnits.Insert(vehicleUnits);

            graph.Actions.PressSave();

        }

        else

        {

            vehicleUnits = PXCache<PEFEVehicleUnits>.CreateCopy(graph.VehicleUnits.Search<PEFEVehicleUnits.unitCD>(unidad.UnidadCD));

              

            vehicleUnits.Description = unidad.Description;

        

            PermisoSCT permisoSCT = PXSelect<PermisoSCT, Where<PermisoSCT.permissionID, Equal<Required<PermisoSCT.permissionID>>>>.Select(this, unidad.PermissionID);

            vehicleUnits.PermissionSCT = permisoSCT.PermissionCD;

        

            vehicleUnits.PermitNumber = unidad.PermitNumber;

        

            ConfiguracionVehicular configuracionVehicular = PXSelect<ConfiguracionVehicular, Where<ConfiguracionVehicular.configuracionVehicularID, Equal<Required<ConfiguracionVehicular.configuracionVehicularID>>>>.Select(this, unidad.ConfiguracionVehicularID);

            vehicleUnits.TransportID = configuracionVehicular.ConfiguracionVehicularCD;

        

            vehicleUnits.AutomobileRegistration = unidad.PlacaActual;

            vehicleUnits.ModelYear = unidad.Modelo;

            vehicleUnits.OwnedOrLeased = "02";

        

            ParteVehiculo parteVehiculo = PXSelect<ParteVehiculo, Where<ParteVehiculo.parteVehiculoID, Equal<Required<ParteVehiculo.parteVehiculoID>>>>.Select(this, unidad.ParteVehiculoID);

            vehicleUnits.PartTransport = parteVehiculo.ParteVehiculoCD;

        

            vehicleUnits.CivilLiabilityInsurerID = unidad.AseguradoraID;

            vehicleUnits.CivilLiabilityPolicyNumber = unidad.NumeroPolizaSeguro;

        

            graph.VehicleUnits.Update(vehicleUnits);

            graph.Actions.PressSave();

        }

    }

        

    protected void Unidad_KilometrajeActual_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)

    {

        Unidad row = (Unidad)e.Row;

        

        decimal? Sumatoria = 0;

  

        if (row == null)

        {

            return;

        }

        if (row.KilometrajeTotal == null)

        {

            row.KilometrajeTotal = row.KilometrajeActual;

        }

        else

        {

            Sumatoria = row.KilometrajeTotal + row.KilometrajeActual;

            row.KilometrajeTotal = Sumatoria;

        }

    }

    public virtual IEnumerable unidadView()

    {

        using (new PXReadBranchRestrictedScope())

        {

            PXResultset<Unidad> Results = PXSelect<Unidad>.Select(this);

    

            foreach (PXResult<Unidad> result in Results)

            {

                Unidad unidad = result;

    

                yield return new PXResult<Unidad>(unidad);

            }

        }

    }

    

    public PXSelect<Unidad> UnidadView;

        

    public PXSave<Unidad> Save;

    public PXCancel<Unidad> Cancel;

    public PXFilter<MasterTable> MasterView;

    public PXFilter<DetailsTable> DetailsView;

    [Serializable]

    public class MasterTable : IBqlTable

    {

    }

    [Serializable]

    public class DetailsTable : IBqlTable

    {

    }

  }

}

Can you help me with this?


3 replies

Userlevel 5
Badge +3

Try this. 

To see all records of your custom DAC regardless of the company or branch that you are logged in, you will need to change the branchID field in your custom DAC to the PXUnbound attribute. This attribute tells Acumatica that the field should not be bound to the database column and should not be used in any database queries.

Here is an example of how you can change the branchID field in your custom DAC:

[PXUnbound]
public virtual int? BranchID { get; set; }
public abstract class branchID : PX.Data.BQL.BqlInt.Field<branchID> { }

Additionally, you will need to update any views or queries that use the branchID field to ignore it and not include it in their filters or where clauses.

It is also important to note that using the PXUnbound attribute may have security implications and can potentially expose sensitive data. Therefore, it is recommended to carefully consider the potential security risks before implementing this solution.

Try this. 

To see all records of your custom DAC regardless of the company or branch that you are logged in, you will need to change the branchID field in your custom DAC to the PXUnbound attribute. This attribute tells Acumatica that the field should not be bound to the database column and should not be used in any database queries.

Here is an example of how you can change the branchID field in your custom DAC:

[PXUnbound]
public virtual int? BranchID { get; set; }
public abstract class branchID : PX.Data.BQL.BqlInt.Field<branchID> { }

Additionally, you will need to update any views or queries that use the branchID field to ignore it and not include it in their filters or where clauses.

It is also important to note that using the PXUnbound attribute may have security implications and can potentially expose sensitive data. Therefore, it is recommended to carefully consider the potential security risks before implementing this solution.

Thanks for your answer @Yuriy Zaletskyy,

I have a little issue, I can’t find the appropriate assembly reference to be able to use it,

\App_RuntimeCode\Unidad.cs(20): error CS0246: The type or namespace name 'PXUnboundAttribute' could not be found (are you missing a using directive or an assembly reference?)

Userlevel 7
Badge

Hi @alejandroalvarado64  were you able to find a solution? Thank you!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved