Solved

Customize an existing view with another condition

  • 12 December 2022
  • 10 replies
  • 423 views

Userlevel 4
Badge +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;

icon

Best answer by Fernando Amadoz 15 December 2022, 20:42

View original

10 replies

Userlevel 7
Badge +8

@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

 

Userlevel 7
Badge +8

@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:

 

 

Userlevel 5
Badge +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>>>();

}

 

Userlevel 7
Badge +8

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

Userlevel 4
Badge +1

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

Userlevel 5
Badge +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.

Userlevel 4
Badge +1

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

 

Userlevel 7
Badge +8

@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.

Userlevel 5
Badge +2

@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>>>>();
}
}
}

 

Userlevel 4
Badge +1

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

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved