Solved

SOS! How to add a restriction to a View on the support case screen in the Portal

  • 4 May 2023
  • 3 replies
  • 71 views

Userlevel 6
Badge +3

This is kind of an SOS

I would normally spend a few days on a project before asking for help, but I’ve been given a fire to put out which has a significant impact on the customer.

On the customer portal, users are able to enter support cases.  I need to limit the support cases that show up in the grid to just cases created by the contact that is logged in.  Right now, all cases are being displayed for any user.  The users are simply contacts for a BAccount “PORTALUSER”.  So, when that contact logs in, they see everything for that baccount.

My thought is to somehow change the view on the grid so that it adds a where condition 

CRCase.contactID =  AccessInfo.contactID.FromCurrent()

It looks like I need to modify the FilteredItems view.

 

 

 

Can I override this?  

Or, is there some way I can override one of the screen events to restrict the Case view?

I’m also trying to find out how I can get the contactID of the current user.

I can get the userID with this code:

            Guid? currentUser = CommonServiceLocator.ServiceLocator.Current.GetInstance<ICurrentUserInformationProvider>().GetUserId();
 

I cannot seem to find how to get the contactID for that user.  I can see that AccessInfo.contactID is a property of AccessInfo, but I don’t know how to get a reference to the “current” of that.

 

icon

Best answer by Joe Schmucker 5 May 2023, 14:58

View original

3 replies

Userlevel 7
Badge +8

Joe if you stuck with getting the ContactID current value then use

int? contactID = PXAccess.GetContactID().GetValueOrDefault();

sorry if there is any typo. I am writing on my cell.

Userlevel 6
Badge +3

@aaghaei Thanks for the tip 

 

This is how I resolved the issue.  I found something similar to this in the Acumatica Training code.

One thing that I had to do is use the UserID of the Contact table in the where clause and compare it to the current logged in userID.  For some reason, the ContactID of the AccessInfo was null.

(AccessInfo.contactID.FromCurrent)

I’ll play with pulling the contactID as your code suggests and maybe I can get it that way.

 

I’ve never done this type of coding in a project before.  This works, but feel free to suggest improvements.  It seems like I should not have to loop through and execute the query, but just pull a result set and return it.  But I guess I have to “yield” each row individually.

 

    public class SPCaseClosedInquiry_Extension : PXGraphExtension<SPCaseClosedInquiry>
    {
        protected virtual IEnumerable filteredItems()
        {

            BqlCommand query;

            query = new SelectFrom<CRCase>
            .LeftJoin<CRCaseClass>
                .On<CRCaseClass.caseClassID.IsEqual<CRCase.caseClassID>>
            .LeftJoin<Contract>
                .On<Contract.contractID.IsEqual<CRCase.contractID>>
            .LeftJoin<BAccount>
                .On<BAccount.bAccountID.IsEqual<CRCase.customerID>>
            .LeftJoin<CRCustomerClass>
                .On<CRCustomerClass.cRCustomerClassID.IsEqual<BAccount.classID>>
            .LeftJoin<Contact2>
                .On<CRCase.ownerID.IsEqual<Contact2.contactID>>
            .LeftJoin<Contact>
                .On<CRCase.contactID.IsEqual<Contact.contactID>>
            .LeftJoin<CRContactClass>
                .On<CRContactClass.classID.IsEqual<Contact.classID>>
            .Where<Brackets<MatchWithBAccountNotNull<CRCase.customerID>>
                .And<CRCase.isActive.IsEqual<False>>
                .And<Brackets<CRCaseClass.isInternal.IsEqual<False>
                    .Or<CRCaseClass.isInternal.IsNull>>>
                .And<Brackets<CRCustomerClass.isInternal.IsEqual<False>
                    .Or<CRCustomerClass.isInternal.IsNull>>>
                .And<Brackets<CRContactClass.isInternal.IsEqual<False>
                    .Or<CRContactClass.isInternal.IsNull>>
                .And<Contact.userID.IsEqual<AccessInfo.userID.FromCurrent>>>>();

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

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

Userlevel 7
Badge

Thank you for sharing your solution with the community @Joe Schmucker !

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