Solved

How to create a View using the Current UserID as a parameter

  • 25 March 2022
  • 5 replies
  • 473 views

Userlevel 6
Badge +3

I am pulling data from a table based on a PXFilter.  One parameter of the Where clause is to pull based on the current logged in User ID.  I created a public variable _currentUser that holds the User ID.

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

How can I pass that value into the Select for the View?  If I put an @P parameter, it compiles.  If I try to use a View.Select(this, _currentUser) to pass in the parameter, I get all kinds of errors. I can’t pass in the actual _currentUser variable because I think it needs to be a type, not a value.

public SelectFrom<QTCAuditHistoryReport>.			Where<QTCAuditHistoryReport.screenID.IsEqual<QTCAuditHistoryReportFilter.screenID.FromCurrent>.
And<QTCAuditHistoryReport.changeDate.IsEqual<QTCAuditHistoryReportFilter.changeDate.FromCurrent>.
And<QTCAuditHistoryReport.reportingUserid.IsEqual<@P.AsGuid>>>>.View.ReadOnly DetailsView;

I think this option would be best but I’m not sure how to do it.

I tried adding the UserID field to the Filter (invisible) so I could just use QTCAuditHistoryReportFilter.userID.FromCurrent.  How would I set the value of a BQL table in the filter to be the UserID?  

 

icon

Best answer by Naveen Boga 25 March 2022, 17:33

View original

5 replies

Userlevel 6
Badge +3

@Naveen Boga , that worked.  

@jinin , just missing the FromCurrent.   SO CLOSE! :-)

THANK YOU BOTH!

Userlevel 7
Badge +17

Hey @joe21  Try this!!

 SelectFrom<QTCAuditHistoryReport>.Where<QTCAuditHistoryReport.screenID.IsEqual<QTCAuditHistoryReportFilter.screenID.FromCurrent>.
            And<QTCAuditHistoryReport.changeDate.IsEqual<QTCAuditHistoryReportFilter.changeDate.FromCurrent>.
                And<QTCAuditHistoryReport.reportingUserid.IsEqual<AccessInfo.userID.FromCurrent>>>>.View.ReadOnly DetailsView;

Userlevel 6
Badge +3

Hi @jinin 

When I put that in the select, I get a red squiggle on the statement saying that it can’t implicitly convert Guid to IBqlGuid

I’m not too savvy with C#.  I tried to cast it (not sure if this syntax is even correct)

<(IBqlGuid)Current<AccessInfo.userID» 

but that doesn’t compile.  Seems closer to the answer though!  Thank you for assisting!

Userlevel 7
Badge +11

Hi @joe21 

you can try with accessInfo.UserID.


public SelectFrom<QTCAuditHistoryReport>.Where<QTCAuditHistoryReport.screenID.IsEqual<QTCAuditHistoryReportFilter.screenID.FromCurrent>. And<QTCAuditHistoryReport.changeDate.IsEqual<QTCAuditHistoryReportFilter.changeDate.FromCurrent>.And<QTCAuditHistoryReport.reportingUserid.IsEqual<Current<AccessInfo.userID>>>>>.View.ReadOnly DetailsView;

Userlevel 6
Badge +3

I don’t think I should be using PXFilter on this form.  Let me try redoing the graph to just be a simple Form/Details not using PXFilter. 

Either way, I’d like to be able to supply the UserID to the SelectFrom.  

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