You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Lookup界面添加选中复选框列并启用多选,求通用实现方法

Great question! When working with Acumatica lookups—like the Price Class selector on the AR209500 Discount screen—and needing to enable multi-select to add multiple records directly to a grid without complex filtering, there are a few streamlined, general-purpose approaches you can use:

1. Use Acumatica's Native LookupMultiSelect Control

This is the most straightforward method, as it’s built specifically for multi-select lookup scenarios. Here’s how to implement it:

  • DAC Setup: If you’re storing selected values, ensure your field can handle multiple entries (either use a string field for comma-separated IDs, or leverage a detail DAC like DiscountDetail on AR209500 for individual records).
  • ASPX Modification: Replace the standard PXLookup control with PXLookupMultiSelect, and configure it to tie directly to your grid’s data view:
    <px:PXLookupMultiSelect ID="edPriceClassID" runat="server" DataField="PriceClassID" 
        CommitChanges="True" DataMember="DiscountDetails" />
    
  • Graph Logic: Add logic to handle selected records and insert them into your grid (avoid duplicates with a quick check):
    protected void DiscountDetails_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {
        var currentDetail = e.Row as DiscountDetail;
        if (currentDetail == null) return;
    
        // Grab all selected Price Classes from the lookup
        var selectedPriceClasses = edPriceClassID.SelectedRecords.Cast<PriceClass>().ToList();
        
        foreach (var pc in selectedPriceClasses)
        {
            // Only add if the Price Class isn't already in the grid
            if (!DiscountDetails.Select().Any(d => d.PriceClassID == pc.PriceClassID))
            {
                var newDetail = new DiscountDetail
                {
                    PriceClassID = pc.PriceClassID,
                    // Populate any required fields (like CompanyID for multi-tenant or DiscountID)
                    DiscountID = Base.Document.Current.DiscountID,
                    CompanyID = Base.Accessinfo.CompanyID
                };
                DiscountDetails.Insert(newDetail);
            }
        }
    }
    
2. Customize the Lookup Dialog with Multi-Select Checkboxes

If you prefer to keep the standard lookup dialog but add checkboxes for multi-selection, you can extend the base lookup graph:

  • Create a Custom Lookup Graph: Inherit from the base lookup graph (e.g., PriceClassMaint) and enable multi-select on the primary data view:
    public class CustomPriceClassLookup : PriceClassMaint
    {
        public PXSelect<PriceClass> PriceClasses;
    
        protected override void Initialize()
        {
            base.Initialize();
            PriceClasses.AllowMultiSelect = true;
        }
    }
    
  • Link the Custom Lookup to Your Control: Update the PXLookup control in your screen’s ASPX to use the custom graph:
    <px:PXLookup ID="edPriceClassID" runat="server" DataField="PriceClassID" 
        LookupGraph="YourNamespace.CustomPriceClassLookup" />
    
  • Handle Selected Records: Add a LookupReturn event handler in your main graph to process selections and add them to the grid:
    protected void edPriceClassID_LookupReturn(PXCache cache, PXLookupReturnEventArgs e)
    {
        var selectedItems = e.ReturnValue as IEnumerable<PriceClass>;
        if (selectedItems == null) return;
    
        foreach (var pc in selectedItems)
        {
            if (!DiscountDetails.Select().Any(d => d.PriceClassID == pc.PriceClassID))
            {
                var newDetail = new DiscountDetail
                {
                    PriceClassID = pc.PriceClassID,
                    DiscountID = Base.Document.Current.DiscountID,
                    CompanyID = Base.Accessinfo.CompanyID
                };
                DiscountDetails.Insert(newDetail);
            }
        }
    }
    
Quick Notes for AR209500

Since you’re targeting the Discount screen, keep in mind that the base DiscountMaint graph already uses the DiscountDetail DAC for Price Class assignments. The LookupMultiSelect approach works especially well here because it directly connects the lookup to the detail data view, minimizing extra code.

Key Considerations

  • Always check for duplicate entries before adding records to avoid grid clutter.
  • Ensure required fields (like CompanyID or parent record IDs) are populated when inserting new rows.
  • Test in your specific Acumatica version, as control behavior can vary slightly between releases.

内容的提问来源于stack exchange,提问作者Rick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:08:50