如何获取当前用户自定义字段warehouse并在任意界面展示?
Hey there! Since you've already created the custom 'warehouse' field in the SM201010 (User Maintenance) screen and saved a value for user1, let's walk through exactly how to use AccessInfo (plus a few key Acumatica tools) to show this field in any other interface.
First, a quick breakdown: AccessInfo is Acumatica's core class that holds context about the currently logged-in user—think username, language preferences, security settings, etc. To pull your custom field, we'll pair it with the user's record from the Users table.
Step 1: Fetch the User Record with Your Custom Field
In your target screen's graph, retrieve the logged-in user's full record (including your custom extension field) using AccessInfo to target the right user. Here's the C# code to do this:
// Grab the current user's context from AccessInfo (built into every Acumatica graph) var currentAccessInfo = Base.Accessinfo; // Query the Users table for the currently logged-in user var currentUser = PXSelect<Users, Where<Users.username, Equal<Current<AccessInfo.username>>>>.Select(Base); // Access your custom 'warehouse' field via the Users extension you created var userExtension = currentUser.GetExtension<UsersExt>(); string userWarehouse = userExtension.Warehouse;
Step 2: Display the Field in Your Target Interface
Once you have the warehouse value, you can show it in your screen in a couple straightforward ways:
Option 1: Direct ASPX Binding
For a simple read-only display, add a label or text box to your ASPX markup and bind it directly to the custom field. Make sure your graph includes a view that references the Users extension:
<!-- Read-only label for the warehouse field --> <px:PXLabel ID="lblWarehouse" runat="server" Text='<%# CurrentUserExtension.Warehouse %>' /> <!-- Disabled text edit for longer text values --> <px:PXTextEdit ID="edWarehouse" runat="server" DataField="Warehouse" Enabled="False" DataSourceID="ds" />
Option 2: Programmatically Set the Value
If you need conditional display or more control, set the control's value directly in your graph's code:
// Assuming you have a PXTextEdit control named edWarehouse in your ASPX edWarehouse.Text = userWarehouse; // Hide the control if the warehouse field is empty edWarehouse.Visible = !string.IsNullOrEmpty(userWarehouse);
Key Things to Keep in Mind
- Permissions: Make sure user1 has read access to the
Userstable and your custom 'warehouse' field in the target screen's security roles. - Cache Refreshing: If you update the warehouse value in SM201010, you may need to clear Acumatica's user cache (System > Management > Clear Cache) to see the new value in other screens.
- Extension Class Validation: Double-check that your custom field is properly defined in the
UsersExtDAC extension—this is what lets you access it viaGetExtension<UsersExt>().
That should get your 'warehouse' field showing up wherever you need it! Let me know if you hit any snags with specific screens or code edge cases.
内容的提问来源于stack exchange,提问作者JackZeng

