You need to enable JavaScript to run this app. Acumatica自定义字段Attribute ID选择器关联填充属性值问题
优惠活动
大模型
产品
解决方案
定价
更多

Acumatica自定义字段Attribute ID选择器关联填充属性值问题

问题根因

你现有代码存在2个核心错误导致无法生效甚至报错:

  • 事件绑定错误:动态修改UsrAttributeValues下拉选项的逻辑被错误绑定到了UsrAttributeSelection的FieldSelecting事件上,该事件仅处理Attribute ID字段本身的取值逻辑,不会作用到属性值字段
  • PXStringState参数配置错误:创建实例时传入的字段长度、字段名等参数和你自定义字段的实际配置不匹配,会触发类型映射错误

修正方案

第一步 调整字段特性

给UsrAttributeSelection的PXUIField特性添加CommitChanges = true,确保选中属性ID后立即触发服务端事件同步值:

namespace MidayaCustomizations
{
    public class APTranExt : PXCacheExtension<PX.Objects.AP.APTran>
    {
        #region UsrAttributeSelection
        [PXDBString(250)]
        [PXUIField(DisplayName = "Attribute ID", CommitChanges = true)]
        [PXSelector(typeof(Search<CSAttribute.attributeID>),
            typeof(CSAttribute.attributeID),
            typeof(CSAttribute.description),
            typeof(CSAttribute.controlType))] 
        public virtual string UsrAttributeSelection { get; set; }
        public abstract class usrAttributeSelection : PX.Data.BQL.BqlString.Field<usrAttributeSelection> { }
        #endregion

        #region UsrAttributeValues
        [PXDBString(250)]
        [PXUIField(DisplayName = "Attribute Values")]
        public virtual string UsrAttributeValues { get; set; }
        public abstract class usrAttributeValues : PX.Data.BQL.BqlString.Field<usrAttributeValues> { }
        #endregion
    }
}

第二步 修正事件逻辑

将事件调整为绑定UsrAttributeValues的FieldSelecting事件,同时修正PXStringState的参数配置:

namespace MidayaCustomizations
{
    public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
    {
        #region Event Handlers
        protected void APTran_UsrAttributeValues_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            APTran row = (APTran)e.Row;
            if (row == null) return;
            var rowExt = row.GetExtension<APTranExt>();
            if (string.IsNullOrEmpty(rowExt.UsrAttributeSelection)) return;

            List<string> allowedValues = new List<string>();
            List<string> allowedLabels = new List<string>();

            foreach (CSAttributeDetail objCSAttributeDetail in PXSelect<CSAttributeDetail,
                Where<CSAttributeDetail.attributeID, Equal<Required<CSAttributeDetail.attributeID>>>>
                .Select(Base, rowExt.UsrAttributeSelection))
            {
                allowedValues.Add(objCSAttributeDetail.ValueID);
                allowedLabels.Add(objCSAttributeDetail.Description);
            }
               
            e.ReturnState = PXStringState.CreateInstance(
                e.ReturnState, 
                250, // 对应字段定义的长度250,不要填10
                true, 
                nameof(APTranExt.usrAttributeValues), 
                false, 
                -1, 
                string.Empty, 
                allowedValues.ToArray(), 
                allowedLabels.ToArray(), 
                false, 
                null);
        }
        #endregion
    }
}

效果验证

重新发布自定义后,打开AP303000页面选择任意明细行的Attribute ID,再点击Attribute Values字段即可看到对应属性的所有可选下拉值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.10 17:03:03