pmfith
pmfith

Reputation: 909

How to default an employeeid field to the current logged in user

I have a custom inquiry screen which uses an employeeid as the header filter field. What I'd like to do is default that employeeid field to the current logged in user, if possible. I've tried the following, but both give me a cast error (version 5.3.2562):

1.)  [PXDBDefault(typeof(Search<EPEmployee.bAccountID, 
                         Where<EPEmployee.bAccountID, Equal<Current<AccessInfo.userID>>>>))]

2.)  [PXDBDefault(typeof(AccessInfo.userID))]

Here's the entire DAC code for the filter field:

    #region EmployeeID
    public abstract class employeeID : IBqlField
    {
    }
    [PXInt]
    [PXDBDefault(typeof(AccessInfo.userID))]
    [PXUIField(DisplayName = "Employee ID")]
    [PXSelector(typeof(Search<EPEmployee.bAccountID,
                       Where<EPEmployee.status, Equal<SetupTypes.active>>>),
                typeof(EPEmployee.acctCD),
                typeof(EPEmployee.acctName),
                SubstituteKey = typeof(EPEmployee.acctCD),
                DescriptionField = typeof(EPEmployee.acctName))]
    public virtual int? EmployeeID { get; set; }
#endregion

What's the correct way to obtain this?

Update 6/30/2017: After implementing the solution (using PXDefault instead of PXDBDefault) as follows:

 [PXDefault(typeof(Search<EPEmployee.bAccountID,
                   Where<EPEmployee.bAccountID, Equal<Current<AccessInfo.userID>>>>))]

I get the following error:

enter image description here

Upvotes: 1

Views: 1171

Answers (2)

jhofer
jhofer

Reputation: 25

AccessInfo.userID seems to be a GUID. In order to avoid the casting error you need to relate AccessInfo.userID to EPEmployee.userID while searching for EPEmployee.bAccountID. Final code should look like this:

    #region EmployeeID
    public abstract class usrEmployeeID : IBqlField
    {
    }
    [PXEPEmployeeSelector]
    [PXUnboundDefault(typeof(Search<EPEmployee.bAccountID,
                 Where<EPEmployee.userID, Equal<Current<AccessInfo.userID>>>>))]
    [PXUIField(DisplayName = "Employee ID")]
    public virtual int? UsrEmployeeID { get; set; }
    #endregion

Upvotes: 1

Brendan
Brendan

Reputation: 5623

We have a non filter field in a transaction able that defaults to the current employee.

This should work:

[PXDefault(typeof(Search<EPEmployee.bAccountID, 
                     Where<EPEmployee.bAccountID, Equal<Current<AccessInfo.userID>>>>))]

Note that you do not want to use PXDBDefault for default values unless they are values coming from a parent DAC when linked with PXParent. Use PXDefault for defaults.

If this does not work in your filter, try PXUnboundDefault in place of PXDefault.

Edit 6/30/2017: new error might be on your selector. There is an employee selector already available. Remove your PXSelector and use [PXEPEmployeeSelector] on your field and see if this solves your error between uniqueidentifier and int

Upvotes: 1

Related Questions