Skip to main content
Answer

How to remove a condition from a View Where on the fly?

  • July 30, 2022
  • 6 replies
  • 224 views

aaghaei
Captain II
Forum|alt.badge.img+10

Hello,

 

I know using View.WhereAnd<> we can ammend the where statements and add a new condition like as i.e.

selectDetails.WhereAnd<Where<PMCostProjectionLine.taskID, Equal<Current<CostProjectionFilter.taskID>>>>();
  1. I was wondering is there a way to remove Where Condition(s) on the fly as well?
  2. Can we reset the Where statements added to the View Query on the fly to the default state before where statements amended?

Best answer by Leonardo Justiniano

Hi @aaghaei 

 

You can use query.WhereNew() to replace the filtering portion of the query.

selectDetails.WhereNew<Where<PMCostProjectionLine.taskID, IsNotNull>>();

Also, you could change the query through a view delegate.

6 replies

Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+4

Hi @aaghaei 

 

You can use query.WhereNew() to replace the filtering portion of the query.

selectDetails.WhereNew<Where<PMCostProjectionLine.taskID, IsNotNull>>();

Also, you could change the query through a view delegate.


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • July 30, 2022

@Leonardo Justiniano thank you. is it possible to remove the WhereAnd which is added on the fly? 


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+4

@aaghaei 

 

WhereNew will replace any filter added previously. 


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • July 30, 2022

Thank you @Leonardo Justiniano I tested this. WhereNew not only removes the conditions added on the fly but also removes the original conditions like as there was no condition from the begining. It is not what I need.


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+4

@aaghaei 

Yes indeed it removes all Where statement. Please add the original condition when calling (WereNew) if you want to keep it or manage your logic to prevent adding a condition (WhereAnd) when really is not needed, so you avoid removing it later in the call. 


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • July 30, 2022

@Leonardo Justiniano it is one of the Acumatica base views and this is developed this way. I can not really keey the Where Statement out of main query. But thank you for your time and help.