Solved

Is there a way to limit the Selector for Price Manager on the Stock Items screen by Role?

  • 20 March 2022
  • 8 replies
  • 98 views

Userlevel 5
Badge +1

I have been asked if there is a way to limit who shows up in the price manager Selector on the Stock Items screen under the Price/Cost tab as in the screenshot below.

I have created a generic inquiry which shows who we want to see. 

It has the following DACS:

Users → UsersInRoles - Inner join on username

Users → Contacts - Inner join on pkID = userID

Condition = UsersInRoles.RoleName Equals Purchasing

This seems to give the restricted set of users/contacts we want.

How do I go about changing the Selector for this field to use this as a the query instead of showing the full list of employees if shows now? 

Thanks for any help,

 

Phil

icon

Best answer by jinin 21 March 2022, 14:14

View original

8 replies

Userlevel 6
Badge +3

hi @ppowell,

We can override base field selector using cacheattached.

Here is the sample.

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXSelector<Write Your Query>]
protected virtual void InventoryItem_PriceManagerID_CacheAttached(PXCache cache)
{
}

Userlevel 5
Badge +1

hi @ppowell,

We can override base field selector using cacheattached.

Here is the sample.

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXSelector<Write Your Query>]
protected virtual void InventoryItem_PriceManagerID_CacheAttached(PXCache cache)
{
}

Thanks. I have been trying to construct a query to go inside <Write your query> but I can’t seem to get a working one.  I’m not entirely sure how to specify that UsersInRoles.RoleName should equal purchasing.

 

I came up with the following but not sure how to implement it in a selector and I know I need to somehow get ‘Purchasing’ into the bit that tells Required<UsersInRoles.Rolename> to use that. I also am not sure how to get from this to the selector returning Contact.ContactID_description which seems to be what this field uses normally or does this somehow get added to the existing definition of the selector and that would be returned automatically?. I’ve been looking at the documentation to get this far but not been able to find anything that specifically applies to this case.

If anyone has pointers for good sources to read I’d be grateful for that too as I’m still trying to get my head around how this stuff works.

 

[PXSelector<Users, InnerJoin<Contact,
                On<Contact.userID, Equal<Users.pKID>>,
                InnerJoin<UsersInRoles,
                On<UsersInRoles.username, Equal<Users.username>,
                And<UsersInRoles.Rolename, Equal<Required<UsersInRoles.Rolename>>>>>>>))]

Thanks,

Phil

Userlevel 5
Badge +1

After looking at it I realised I’m working about this the wrong way and should probably be doing it from Contact in the first place. 

I feel like I'm getting closer but still not there yet:

So SQL equivalent would be as below:

SELECT Contact.ContactID_description
FROM Contact
INNER JOIN Users
ON Contact.UserID = Users.pKID
INNER JOIN UsersInRoles
ON UsersInRoles.username = Users.username
WHERE
UsersInRoles.Rolename = 'Purchasing'

so the equivalent BQL would be:

<Select<Contact.ContactID_description, InnerJoin<Users, On<Contact.UserID, Equal<Users.pKID>>,
InnerJoin<UsersInRoles, On<UsersInRoles.username, Equal<Users.username>>, Where<UsersInRoles.Rolename, Equal<'Purchasing'>>>>>>>>>

but I don't think it's the right syntax and I still don't know how to specify 'Purchasing'.

Thanks,

Phil

Userlevel 7
Badge +11

Hi @ppowell 

You can write the BQL like below. Add a constant value for the user role and assign it to the field.

 [PXSelector(typeof(Search2<Contact.contactID,
            InnerJoin<Users, On<Contact.userID, Equal<Users.pKID>>,
                InnerJoin<UsersInRoles, On<UsersInRoles.username, Equal<Users.username>>>>,
            Where<UsersInRoles.rolename,
            Equal<purchasing>>>), DescriptionField = typeof(Contact.fullName), DirtyRead = true)]


 public class purchasing : BqlString.Constant<purchasing> { public purchasing() : base("Purchasing") { } }

Userlevel 5
Badge +1

Thanks so much.  I had got to the following last night after reading various sources and trial and error, but I had a problem where the Contact ID was being displayed alongside the displayName, I guess because it was being merged in. I was missing the DescriptionField part of PXSelector.

You have been a great help.

 

private class PurchRole : Constant<string>
    {
      public PurchRole() : base("Purchasing")
      {
      }
    }

[PXSelector(typeof(Search2<Contact.contactID, InnerJoin<Users, On<Users.pKID, Equal<Contact.userID>>, InnerJoin<UsersInRoles, On<UsersInRoles.username, Equal<Users.username>>>>, Where<UsersInRoles.rolename, Equal<PurchRole>>>))]


  

 

Userlevel 5
Badge +1

Now I’m confused.  I thought the DescriptionField part was supposed to determine what is shown in the field but the field still displays the contactID and displayname like: (12345 - Phil Powell) after I select a contact from the Selector.

Is there a way to get it to just show the name?

Thanks,

Phil 

Userlevel 7
Badge +11

Hi @ppowell 

To show the name instead of ID, you can add the subtitutekey as ID and search with the full name. I did a small change on the BQL, please try with the below one. 

   [PXSelector(typeof(Search2<Contact.fullName,
            InnerJoin<Users, On<Contact.userID, Equal<Users.pKID>>,
                InnerJoin<UsersInRoles, On<UsersInRoles.username, Equal<Users.username>>>>,
            Where<UsersInRoles.rolename,
            Equal<purchasing>>>),  SubstituteKey = typeof(Contact.contactID), DirtyRead = true)]
 

Userlevel 5
Badge +1

I discovered the problem.  The field wasn’t set to DisplayMode=Text.  Once I set that the first DescriptionField method worked perfectly.

Thanks so much for all your help.

Phil

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