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

Acumatica 6.10: Kit Assembly网格InventoryItem属性列无值问题求助

解决Acumatica Kit Assembly屏幕Stock Components网格无法获取InventoryItem属性值的问题

看起来你已经走对了方向,成功在Stock Components网格里渲染出了属性列,但问题出在属性值的关联源和取值逻辑上。咱们一步步拆解问题并修正代码:

核心问题分析

  1. 关联的实体错误:你的自定义属性用了INComponentTran.noteID,但InventoryItem的属性是存储在InventoryItem实体的记录里,不是INComponentTran。所以需要关联到对应组件的InventoryItem的noteID和itemClassID,而不是组件交易行的。
  2. 拼写错误:类名PXAddAtttributeColumns多了一个t(应该是PXAddAttributeColumns),虽然不影响编译,但容易造成混淆。
  3. 缺失属性值的获取逻辑:当前代码只处理了列的显示设置,但没有从对应的InventoryItem记录中读取属性值。

修正后的完整代码

using System;
using System.Linq;
using PX.Data;
using PX.Objects.IN;
using PX.Objects.CR;

public class PXAddAttributeColumns : CRAttributesFieldAttribute 
{
    private readonly string[] _attributeNames;

    public PXAddAttributeColumns(string[] attributeNames, Type inventoryItemClassID, Type inventoryItemNoteID) 
        : base(inventoryItemClassID, inventoryItemNoteID) 
    {
        _attributeNames = attributeNames;
    }

    public override void CacheAttached(PXCache sender)
    {
        _IsActive = true;
        base.CacheAttached(sender);
    }

    protected override void AttributeFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, PXFieldState state, string attributeName, int idx)
    {
        // 只处理我们指定的属性
        if (_attributeNames.Any(name => name.Equals(attributeName, StringComparison.OrdinalIgnoreCase)))
        {
            state.DisplayName = !string.IsNullOrEmpty(state.DisplayName) 
                ? state.DisplayName.Replace("$Attributes$-", "") 
                : attributeName;
            state.Visible = true;
            state.Visibility = PXUIVisibility.Dynamic;

            // 关键:获取当前组件对应的InventoryItem记录,读取属性值
            if (e.Row is INComponentTran componentTran)
            {
                InventoryItem item = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<INComponentTran.inventoryID>>>>
                    .Select(sender.Graph, componentTran.InventoryID);
                
                if (item != null)
                {
                    // 从InventoryItem的属性中获取对应值
                    var itemAttributes = sender.GetValue(item, nameof(InventoryItem.Attributes)) as string[];
                    if (itemAttributes != null && idx < itemAttributes.Length)
                    {
                        state.Value = itemAttributes[idx];
                    }
                }
            }
        }
        base.AttributeFieldSelecting(sender, e, state, attributeName, idx);
    }
}

public class INComponentTranExtension : PXCacheExtension<INComponentTran>
{
    public abstract class itemAttributes : IBqlField { }

    // 修正:关联InventoryItem的itemClassID和noteID,不是INComponentTran的
    [PXAddAttributeColumns(
        new[] { "Attrib101" }, 
        typeof(InventoryItem.itemClassID), 
        typeof(InventoryItem.noteID))]
    [PXUIField(DisplayName = "Item Attributes")]
    public virtual string[] ItemAttributes { get; set; }
}

关键修正点说明

  • 关联正确的实体字段:在PXAddAttributeColumns的构造参数中,我们传入InventoryItem.itemClassID和InventoryItem.noteID,让属性系统知道要从InventoryItem的属性配置中读取。
  • 添加属性值获取逻辑:在AttributeFieldSelecting方法中,通过当前INComponentTran的InventoryID查询对应的InventoryItem记录,然后从该记录的Attributes字段中提取对应属性的值,赋值给state.Value。
  • 修正类名拼写:把PXAddAtttributeColumns改为PXAddAttributeColumns,避免不必要的混淆。

额外验证步骤

  1. 确保Attrib101是你在Inventory Item Class中定义的属性编码,大小写要匹配(或者代码里用忽略大小写的判断)。
  2. 发布自定义后,打开Kit Assembly屏幕,查看Stock Components网格的新增列是否已经正确显示对应Inventory Item的属性值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 07:30:35