I have a custom screen with a custom grid. On that grid, the user can lookup the customer. In my current DAC field, it is restricting the customers to be returned based on whether the current user is linked to the Salesperson.
For the customer nbr field in either the header or the grid, I am restricting the selector to only return customers where the current user is a salesperson on that customer.
Thie is the DAC field for the grid.
#region UsrCustomerID
[CustomerActive()]
[PXUIField(DisplayName = "Customer Nbr.", Required = true)]
[PXSelector(typeof(Search2<Customer.bAccountID,
InnerJoin<ICSCustomerSalesPersonLinksSQLView, On<ICSCustomerSalesPersonLinksSQLView.customerID, Equal<Customer.bAccountID>>>,
Where<ICSCustomerSalesPersonLinksSQLView.userID.IsEqual<AccessInfo.userID.FromCurrent>>>),
typeof(Customer.acctCD),
typeof(Customer.acctName),
SubstituteKey = typeof(Customer.acctCD))]
[PXDefault]
public virtual int? UsrCustomerID { get; set; }
public abstract class usrCustomerID : PX.Data.BQL.BqlInt.Field<usrCustomerID> { }
#endregionI want to make it so that if the currently logged in user is in the Admin class, they can see all the customers. This means that the where clause in my dac field needs to be removed.
Is this easy to do?
I found some articles along this theme, but I was not able to follow them and adapt them to my code.
From this one:
It looks like this might be the direction I need to go in.
This is what I am working with. It is not complete and I don’t even know if this is how I should be doing this.
My guess is that I remove the where clause from the selector and use this code to do the logic:
[PXMergeAttributes(Method = MergeMethod.Merge)]
[NEWCustomSelector(typeof(ICSCallLog.usrCustomerID))]
protected virtual void Filter_UsrCustomerID_CacheAttached(PXCache cache)
{
}
[Serializable]
public class NEWCustomSelector : PXCustomSelectorAttribute
{
public NEWCustomSelector(Type type)
: base(type, typeof(ICSCallLog.usrCustomerID))
{
}
public virtual IEnumerable GetRecords()
{
ICSCallLog currentItem = (ICSCallLog)this._Graph.Views["ICSCallLogView"].Cache.Current;
if (currentItem == null) return null;
//had to do this to be able to do a PXSelect
PXGraph g = new PXGraph();
UsersInRoles objUsers = PXSelect<UsersInRoles, Where<UsersInRoles.username, Equal<Current<AccessInfo.userName>>,
And<UsersInRoles.rolename, Equal<@P.AsString>>>>.Select(g, "Admin");
if (objUsers != null)
{
//admin so allow everything
//is this where I add or allow thie customer?
}
else
{
//see if the current user is a salesperson for the customer
//is this where I add or allow thie customer?
}
//HOW DO I RETURN THIS?
}
}
Thanks in advance for any suggestions!
