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

如何在Acumatica中为网格每行动态加载差异化下拉选项?

How to Load Targeted Dropdown Options per Query in Acumatica's FieldSelecting Event

Hey there! Let's break down how to fix this so you get the right dropdown options for each query type (like only 3 values for Fuel Type queries).

First, let's look at what your current code is doing: it's pulling all KNRWTAXResponse records linked to any KNRWTAXQueries tied to the current inventory ID. That's why you're seeing every possible response, not the filtered set you need.

The Fix: Filter Responses Based on Query Type

The key here is to identify what makes a query a "Fuel Type" query (or any other specific query type) — I assume your KNRWTAXQueries table has a field like QueryName, QueryType, or some unique identifier you can use to distinguish it. Let's use QueryName as an example.

Here's how to adjust your code:

  1. Check the current query's type before fetching responses.
  2. Filter the KNRWTAXResponse records to only include the ones relevant to that query type.
  3. Optimize the query to avoid unnecessary nested loops (we can fetch the exact responses we need in one go instead of iterating through all queries first).

Modified Code Example

protected virtual void KNRWTAXQueries_Response_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
    KNRWTAXQueries doc = e.Row as KNRWTAXQueries;
    if (doc == null) return;

    List<string> responseValues = new List<string>();
    List<string> responseLabels = new List<string>();

    // First, get the current query's unique identifier (adjust the field to match your schema)
    string currentQueryName = doc.QueryName; // Replace with your actual field, e.g., doc.Taxqueid if you use IDs

    // Fetch ONLY the responses linked to the current query
    foreach (KNRWTAXResponse response in PXSelect<KNRWTAXResponse, 
        Where<KNRWTAXResponse.tAXQueID, Equal<Required<KNRWTAXQueries.taxqueid>>>>.Select(Base, doc.Taxqueid))
    {
        // Add conditional logic to filter responses for specific query types
        if (currentQueryName.Equals("Fuel Type", StringComparison.OrdinalIgnoreCase))
        {
            // Only add the 3 specific values you need for Fuel Type
            if (new List<string> { "Gasoline", "Diesel", "Electric" }.Contains(response.Response))
            {
                responseValues.Add(response.Response);
                responseLabels.Add(response.Response);
            }
        }
        else
        {
            // For other queries, add all their linked responses (or add other filters here)
            responseValues.Add(response.Response);
            responseLabels.Add(response.Response);
        }
    }

    // Update the field state with the filtered options
    if (responseValues.Any())
    {
        e.ReturnState = PXStringState.CreateInstance(
            e.ReturnState, 
            255, 
            true, 
            typeof(KNRWTAXQueries.response).Name, 
            false, 
            1, 
            string.Empty, 
            responseValues.ToArray(), 
            responseLabels.ToArray(), 
            true, 
            null);
    }
}

Key Notes:

  • Adjust the query identifier: Replace doc.QueryName with the actual field in KNRWTAXQueries that lets you tell apart query types (could be an ID, a code, etc.).
  • Customize the filter logic: For "Fuel Type", I hardcoded the 3 values, but you could also pull these from a separate setup table if you want them to be configurable instead of hardcoded.
  • Optimize the data fetch: We removed the nested loop over KNRWTAXQueries because we only care about the current query (doc) that's triggering the FieldSelecting event — no need to loop through all queries for the inventory ID.

If you don't have a QueryName field, you could also use the Taxqueid directly (if each query type has a fixed ID). For example:

if (doc.Taxqueid == 123) // 123 is the ID for Fuel Type queries
{
    // Filter responses here
}

That should give you the targeted dropdown options you need for each query type.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 18:02:38