Skip to main content
Answer

SelectFrom with order by and where part

  • October 13, 2023
  • 3 replies
  • 173 views

Forum|alt.badge.img

Hi Team,

Need know how to write bql query with order by and where part. Can someone help me?

My Sample

[PXFilterable]
        public SelectFrom<HMRCVendorRegisterDetail>.OrderBy<Desc<HMRCVendorRegisterDetail.validTo>>.Where<HMRCVendorFilter.bAccountID.FromCurrent.IsNull.Or<HMRCVendorRegisterDetail.bAccountID.IsEqual<HMRCVendorFilter.bAccountID.FromCurrent>>>.View.ReadOnly DetailsView;

Best answer by Django

I searched through the Acumatica code for .OrderBy< and found this example:

public SelectFrom<ContactAccount>
.Where<
ContactAccount.bAccountID.IsEqual<CRLead.bAccountID.FromCurrent>
.And<ContactAccount.contactType.IsEqual<ContactTypesAttribute.person>>
>
.OrderBy<
ContactAccount.isPrimary.Desc,
ContactAccount.displayName.Asc
>
.View Link_SelectEntityForLink;

 

3 replies

Forum|alt.badge.img+5
  • Jr Varsity II
  • October 13, 2023

Your Where conditions should be before the OrderBy section. 

SelectFrom<Table>.Where<WhereConditions>.OrderBy<Desc<Table.Field>>.View.ReadOnly DetailsView;

 


Forum|alt.badge.img+7
  • Captain II
  • Answer
  • October 13, 2023

I searched through the Acumatica code for .OrderBy< and found this example:

public SelectFrom<ContactAccount>
.Where<
ContactAccount.bAccountID.IsEqual<CRLead.bAccountID.FromCurrent>
.And<ContactAccount.contactType.IsEqual<ContactTypesAttribute.person>>
>
.OrderBy<
ContactAccount.isPrimary.Desc,
ContactAccount.displayName.Asc
>
.View Link_SelectEntityForLink;

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • October 14, 2023

@bhagyat25  Below is the query for your query and hope this helps!!

 

        public PXSelect<HMRCVendorRegisterDetail,Where<HMRCVendorFilter.bAccountID, IsNull, Or<HMRCVendorRegisterDetail.bAccountID, Equal<Current<HMRCVendorFilter.bAccountID>>>>,
OrderBy<Desc<HMRCVendorRegisterDetail.validTo>> DetailsView;