Skip to main content

I have a custom form and I want to do filtering on the View.  I’ve had a similar issue in the past which I resolved on this previous post:

 

I’m following the same principles in my code here, but I am getting an error.

In my override, my BqlCommand is EXACTLY the same as the original view select statement.  I was just ensuring that the code would work before making any changes to the BqlCommand.

public SelectFrom<ICSFSSScheduleLine>
.Where<ICSFSSScheduleLine.scheduleID.IsEqual<ICSFSSSchedule.scheduleID.FromCurrent>>
.OrderBy<Asc<ICSFSSScheduleLine.lower>, Asc<ICSFSSScheduleLine.upper>, Asc<ICSFSSScheduleLine.cutoffDate>>
.View DetailsView;

protected virtual IEnumerable detailsView()
{
ICSFSSSchedule currentRecord = ScheduleView.Current;

BqlCommand query;

//plan to do stuff here to change the query based on other factors

query = new SelectFrom<ICSFSSScheduleLine>
.Where<ICSFSSScheduleLine.scheduleID.IsEqual<ICSFSSSchedule.scheduleID.FromCurrent>>
.OrderBy<Asc<ICSFSSScheduleLine.lower>, Asc<ICSFSSScheduleLine.upper>, Asc<ICSFSSScheduleLine.cutoffDate>>();

var view = new PXView(this, true, query);

foreach (PXResult<ICSFSSScheduleLine> item in view.SelectMulti(null))
{
yield return item;
}
}

 

When the foreach (PXResult<ICSFSSScheduleLine> item in view.SelectMulti(null)) fires, I get this error:

My code is almost a literal cut and paste from my other post linked above which worked.

I’m stumped.

 

Hi @Joe Schmucker Little bit modified your code. Please find updated code below.

As you are using single table in your VIEW, PXResult is not required.

 

    public SelectFrom<ICSFSSScheduleLine>
.Where<ICSFSSScheduleLine.scheduleID.IsEqual<ICSFSSSchedule.scheduleID.FromCurrent>>
.OrderBy<Asc<ICSFSSScheduleLine.lower>, Asc<ICSFSSScheduleLine.upper>, Asc<ICSFSSScheduleLine.cutoffDate>>
.View DetailsView;

protected virtual IEnumerable detailsView()
{
ICSFSSSchedule currentRecord = ScheduleView.Current;

BqlCommand query;

//plan to do stuff here to change the query based on other factors

//PXSelectBase query = new SelectFrom<ICSFSSScheduleLine>
// .Where<ICSFSSScheduleLine.scheduleID.IsEqual<ICSFSSSchedule.scheduleID.FromCurrent>>
// .OrderBy<Asc<ICSFSSScheduleLine.lower>, Asc<ICSFSSScheduleLine.upper>, Asc<ICSFSSScheduleLine.cutoffDate>>();

PXSelectBase<ICSFSSScheduleLine> query = new PXSelect<ICSFSSScheduleLine, Where<ICSFSSScheduleLine.scheduleID,Equal<Current<ICSFSSSchedule.scheduleID>>>,
OrderBy<Asc<ICSFSSScheduleLine.lower>, Asc<ICSFSSScheduleLine.upper>, Asc<ICSFSSScheduleLine.cutoffDate>>>();


if (VIEW.Current.Field != null)
{
query.WhereAnd<Where<ICSFSSScheduleLine.AnyFieldName, Equal<Current<DAC.FieldName>>>>();
}

foreach (ICSFSSScheduleLine item in view.Select(this))
{
yield return item;
}
}

 


Thank you @Naveen Boga!  

In case anyone finds this post, here is the full working version of my code.  I had to make a couple of tweaks to Naveen’s code (one was to add “this” to the select statement).

protected virtual IEnumerable detailsView()
{
ICSFSSSchedule currentRecord = ScheduleView.Current;
Filter filter = FilterView.Select();

PXSelectBase<ICSFSSScheduleLine> query = new PXSelect<ICSFSSScheduleLine,
Where<ICSFSSScheduleLine.scheduleID, Equal<Current<ICSFSSSchedule.scheduleID>>>,
OrderBy<Asc<ICSFSSScheduleLine.lower, Asc<ICSFSSScheduleLine.upper, Asc<ICSFSSScheduleLine.cutoffDate>>>>>(this);

if (filter != null && filter.LowerInt != null && filter.UpperInt != null && currentRecord != null)
{
query.WhereAnd<Where<ICSFSSScheduleLine.lowerInt, Equal<Current<Filter.lowerInt>>,
And<ICSFSSScheduleLine.upperInt, Equal<Current<Filter.upperInt>>>>>();
}

foreach (ICSFSSScheduleLine item in query.Select())
{
yield return item;
}
}

 


Thanks for sharing the full code for reference @Joe Schmucker 


Reply