Skip to main content

Hello,

I’m trying to resolve the following issue: custom column added to the grid contains no data.

Here are the details.

I am trying to customize the Run Service Contract Billing (FS501300) form to add Organization ID column into its Contracts grid.

To do that I extended the ContractPeriodToPost DAC for the grid based on the following article: https://blog.zaletskyy.com/post/2020/03/09/post100 .
My extension is as following.

using PX.Data;

using PX.Data.BQL;

using PX.Objects.GL;

namespace PX.Objects.FS

{

    public class ContractPeriodToPostExt : PXCacheExtension<ContractPeriodToPost>

    {

        public static bool IsActive() => true;

        #region UsrCompanyID

        IPXInt]

         PXUIField(DisplayName = "Organization ID")]

        gPXDBScalar(typeof(Search<Branch.organizationID, Where<Branch.branchID, Equal<ContractPeriodToPost.branchID>>>))]

        public virtual int? UsrCompanyID { get; set; }

        public abstract class usrCompanyID : BqlInt.Field<usrCompanyID> { }

        #endregion

    }

}

Then using Screen Editor, I added UsrCompanyID (Organization ID) control of type NumberEdit to the Grid.
As a result, the Contracts grid now has the Organization ID column, however it doesn’t contain any data.

The grid though successfully displays all the data for all the other columns.

What should I do to display data in the Organization ID column?

Thank you!

 

Hi @ntabunidze57 

 

PXDBScalar should work in your scenario (A Projection). PXDBScalar & Projections

However and alternative to it is using PXUnboundDefault instead

 

#region UsrCompanyID

rPXInt]
rPXUIField(DisplayName = "Organization ID")]
rPXUnboundDefault(typeof(Search<Branch.organizationID, Where<Branch.branchID, Equal<Current<ContractPeriodToPost.branchID>>>>))]
public virtual int? UsrCompanyID { get; set; }
public abstract class usrCompanyID : BqlInt.Field<usrCompanyID> { }

#endregion

Note that ContractPeriodToPost.branchID reference requires the Current<> one. This is because PXUnboundDefault is resolved after the record is retrieved, executing the specified BQL for that record.

 


Thank you, Leonardo!

[PXUnboundDefault] works for me.


@Leonardo Justiniano the alternative approach that we had discussed via events is this one:


protected virtual void _(Events.FieldSelecting<DACExt.usrCompanyID> e)
{
if (e.Row == null)
{
return;
}

Branch branchRow = PXSelect<Branch,
Where<Branch.branchID, Equal<Required<Branch.branchID>>>>
.Select(this.Base, ContractPeriodToPost.branchID);

if (branchRow != null)
{
e.ReturnValue = branchRow.OrganizationID;
}
}

I have not tested this logic. It’s an adaptation from similar logic that we have implemented in the past.

 

Having said that, your approach via PXUnboundDefault attribute is better.


@Fernando Amadoz 

 

Thanks! Alternative approaches are super valuable.


Reply