Skip to main content
Answer

Customize an existing view with another condition

  • December 12, 2022
  • 10 replies
  • 782 views

Forum|alt.badge.img+1

Hi all,

I want to customize following view to filter SOOrders with Open Status. How can I do that?

public PXSelectJoin<SOOrder,LeftJoin<Users, On<Users.pKID, Equal<SOOrder.createdByID>>,            LeftJoin<SOOrderType, On<SOOrderType.orderType, Equal<SOOrder.orderType>>,            LeftJoin<PX.Objects.GL.Branch, On<PX.Objects.GL.Branch.branchID, Equal<SOOrder.branchID>>,            LeftJoin<Organization, On<Organization.organizationID, Equal<PX.Objects.GL.Branch.organizationID>, Or<Organization.organizationID, IsNull>>, LeftJoin<PortalSetup, On2<Where<PortalSetup.restrictByOrganizationID, IsNull, Or<Organization.organizationID, Equal<PortalSetup.restrictByOrganizationID>>>,                 And<Where<PortalSetup.restrictByBranchID, IsNull, Or<PX.Objects.GL.Branch.branchID, Equal<PortalSetup.restrictByBranchID>>>>>>>>>>, Where2<MatchWithBAccount<SOOrder.customerID, Current<AccessInfo.userID>>,                 And<PortalSetup.IsCurrentPortal>>, OrderBy<Desc<SOOrder.orderNbr>>> Items;

Best answer by Fernando Amadoz

@charithalakshan49 @aaghaei 

Just clarifying:
WhereNew<> requires to re-define the complete Where clause
WhereAnd<> appends a new clause using the And logical operator.

Something along these lines (I have not tested it though):

public override void Initialize()
{

this.Base.Items.WhereAnd<Where<SOOrder.status, Equal<SOOrderStatus.open>>>();

}

----
----
----

You can find a reference in Acumatica source code > APUpdateDiscountsVisibilityRestriction:

using PX.Data;
using PX.Objects.CS;

namespace PX.Objects.AP
{
public class APUpdateDiscountsVisibilityRestriction : PXGraphExtension<APUpdateDiscounts>
{
public static bool IsActive()
{
return PXAccess.FeatureInstalled<FeaturesSet.visibilityRestriction>();
}

public override void Initialize()
{
base.Initialize();

Base.NonPromotionSequences.WhereAnd<Where<Vendor.vOrgBAccountID, RestrictByUserBranches<Current<AccessInfo.userName>>>>();
Base.Sequences.WhereAnd<Where<Vendor.vOrgBAccountID, RestrictByUserBranches<Current<AccessInfo.userName>>>>();
}
}
}

 

10 replies

aaghaei
Captain II
Forum|alt.badge.img+10
  • Captain II
  • December 12, 2022

@charithalakshan49

If it’s a public out of box view in Acumatica graph, you need to write a view delegate and append  the where statement. If you want to keep everything as is and add a condition then you can use WhereAnd to add extra condition in your delegate. There are quite a few examples for view delegate on community that you can utilize and edit.

please note the delegate must have the same name of original view but the first letter should be in lower case.

here is a guide:

https://asiablog.acumatica.com/2016/06/using-pxview-in-dataview-delegate.html

 


aaghaei
Captain II
Forum|alt.badge.img+10
  • Captain II
  • December 12, 2022

@charithalakshan49  In addition to my previous comment, I found my earlier case that I had a little bit more complex requirements that I did something and I’m confident you will extract what you need from it and ignore the rest. Here is my post from sometime ago:

 

 


Fernando Amadoz
Jr Varsity I
Forum|alt.badge.img+2

@charithalakshan49 

you have a couple of options to go about this:

1 - You could redefine the Data view in your Graph Extension.
Here is more info on how to do that.

2 - You could add additional filtering elements in the Graph Extension’s Initialize() method.

It would look something like:

public override void Initialize()
{

this.Base.Items.WhereNew<Where<SOOrder.status, Equal<SOOrderStatus.open>>>();

}

 


aaghaei
Captain II
Forum|alt.badge.img+10
  • Captain II
  • December 13, 2022

@Fernando Amadoz WhereNew will remove the existing Where Statement completely and replace with your new Where statement


Forum|alt.badge.img+1

@Fernando Amadoz  @aaghaei Thanks for the responses. I will try these things.


Fernando Amadoz
Jr Varsity I
Forum|alt.badge.img+2

@charithalakshan49:

@aaghaei is correct in his statement. Good catch.
WhereNew will fully replace the content of the original Where clause.
Take that in consideration if you decide to go with that approach.


Forum|alt.badge.img+1

@aaghaei Yes he is correct. So if I use that approach, what should I use instead of WhereNew<>?

 


aaghaei
Captain II
Forum|alt.badge.img+10
  • Captain II
  • December 15, 2022

@charithalakshan49 
 

Generally to append where statement you need to use WhereAnd<> or WhereOr<> then call the view. If you look into my post link 

https://community.acumatica.com/customizations%2D187/how%2Dto%2Dfilter%2Da%2Dview%2Ddelegate%2Dand%2Dsort%2Dthe%2Dreturn%2Dresult%2D9924

and search for WhereAnd you will see how it is developed.


Fernando Amadoz
Jr Varsity I
Forum|alt.badge.img+2
  • Jr Varsity I
  • Answer
  • December 15, 2022

@charithalakshan49 @aaghaei 

Just clarifying:
WhereNew<> requires to re-define the complete Where clause
WhereAnd<> appends a new clause using the And logical operator.

Something along these lines (I have not tested it though):

public override void Initialize()
{

this.Base.Items.WhereAnd<Where<SOOrder.status, Equal<SOOrderStatus.open>>>();

}

----
----
----

You can find a reference in Acumatica source code > APUpdateDiscountsVisibilityRestriction:

using PX.Data;
using PX.Objects.CS;

namespace PX.Objects.AP
{
public class APUpdateDiscountsVisibilityRestriction : PXGraphExtension<APUpdateDiscounts>
{
public static bool IsActive()
{
return PXAccess.FeatureInstalled<FeaturesSet.visibilityRestriction>();
}

public override void Initialize()
{
base.Initialize();

Base.NonPromotionSequences.WhereAnd<Where<Vendor.vOrgBAccountID, RestrictByUserBranches<Current<AccessInfo.userName>>>>();
Base.Sequences.WhereAnd<Where<Vendor.vOrgBAccountID, RestrictByUserBranches<Current<AccessInfo.userName>>>>();
}
}
}

 


Forum|alt.badge.img+1

@Fernando Amadoz @aaghaei Thanks For the responses!.🤝