【问题标题】:How to get the value of a custom field from another project如何从另一个项目中获取自定义字段的值
【发布时间】:2020-12-23 15:25:24
【问题描述】:

早上好,

我在项目屏幕的第一个自定义项目中自定义了两个字段。除了在另外两个自定义项目中,正在对 UsrBaseIndex 字段进行 pxselector,将“PMAddressExt.usrCounty”字段作为参数传递,但我注意到它没有显示信息,这可能表明我做错了。

附上图片以便更好地理解。

提前致谢。

项目 1

namespace PX.Objects.PM
{
    public class PMAddressExt : PXCacheExtension<PX.Objects.PM.PMAddress>
    {
        #region UsrGeocode
                                                                        [PXDBString(30)]
        [PXUIField(DisplayName="Geo code")]

        public virtual string UsrGeocode { get; set; }
        public abstract class usrGeocode : PX.Data.BQL.BqlString.Field<usrGeocode> { }
        #endregion

        #region UsrCounty

[PXDBInt]
        [PXUIField(DisplayName="County")]

[PXSelector(
        typeof(PESKCounty.countyID),
        typeof(PESKCounty.countyCD),
        typeof(PESKCounty.countyName),
        DescriptionField = typeof(PESKCounty.countyName),
        SubstituteKey = typeof(PESKCounty.countyCD))]

        [PXRestrictor(typeof(Where<PESKCounty.stateID, Equal<Current<PMSiteAddress.state>>>), "", typeof(PESKCounty.stateID))]
        public virtual int? UsrCounty { get; set; }
        public abstract class usrCounty : PX.Data.BQL.BqlInt.Field<usrCounty> { }
        #endregion
    }
}

项目 2

namespace PX.Objects.CT
{
    public class ContractExt : PXCacheExtension<PX.Objects.CT.Contract>
    {
        #region UsrSPriceIndex
                        [PXDBBool]
        [PXUIField(DisplayName = "Subject to Price Index")]

        public virtual bool? UsrSPriceIndex { get; set; }
        public abstract class usrSPriceIndex : PX.Data.BQL.BqlBool.Field<usrSPriceIndex> { }
        #endregion

        #region UsrPRCNumber
                
        [PXDBInt]
        [PXUIField(DisplayName = "PRC Number")]
        [PXSelector(typeof(Search2<PESKPRC.recordID,
                InnerJoin<PESKCountyPriceIndexDetail, On<PESKCountyPriceIndexDetail.recordID, Equal<PESKPRC.recordID>>>,
                Where<PESKPRC.availabletoAll, Equal<True>,
                     And<PESKPRC.active, Equal<True>
                         //And<PESKCountyPriceIndexDetail.countyID, Equal<Current<PMAddressExt.usrCounty>>>
                         >>>),
                typeof(PESKPRC.prcnbr),
                typeof(PESKCountyPriceIndexDetail.pRCPriceIndexCD),
                SubstituteKey = typeof(PESKPRC.prcnbr)
                )]

        public virtual int? UsrPRCNumber { get; set; }
        public abstract class usrPRCNumber : PX.Data.BQL.BqlInt.Field<usrPRCNumber> { }
        #endregion

        #region UsrBaseIndex

        [PXDBInt]
        [PXUIField(DisplayName = "Base Index")]
        [PXSelector(typeof(Search<PESKViewBaseIndex.priceIndexID,
            Where<PESKViewBaseIndex.recordID, IsNull
                ,And<PESKViewBaseIndex.countyID, Equal<Current<PMAddressExt.usrCounty>>,
                    Or<PESKViewBaseIndex.countyID,IsNull>
                    >
                >>),
        typeof(PESKViewBaseIndex.pRCPriceIndexCD),
        SubstituteKey = typeof(PESKViewBaseIndex.pRCPriceIndexCD),ValidateValue =false)]
        public virtual int? UsrBaseIndex { get; set; }
        public abstract class usrBaseIndex : PX.Data.BQL.BqlInt.Field<usrBaseIndex> { }
        #endregion

        #region UsrPCNumber
                        [PXDBString(60)]
        [PXUIField(DisplayName = "PCNumber")]

        public virtual string UsrPCNumber { get; set; }
        public abstract class usrPCNumber : PX.Data.BQL.BqlString.Field<usrPCNumber> { }
        #endregion
    }
}

【问题讨论】:

  • 由于你在第二个项目中使用的是第一个项目,这意味着你已经引用了它。因此,您不需要在第二个字段中复制第一个字段,因为您可以访问它的值。您的“县”字段是否设置了 CommitChanges = "True"?您的“基本索引”字段是否设置了 AutoRefresh = "True"(这是根据县字段的新值重新加载选择器中的值)?您能否使用 SQL 探查器检查查询,以查看选择器正在查找的内容以及查询是否良好以及直接在数据库中执行时是否有结果?

标签: acumatica acumatica-kb


【解决方案1】:

您应该在第二个项目中为 PMAdress 添加一个新扩展名,然后在该扩展名中添加一个新字段,以便从第一个项目中获取 County 的值。

public sealed class PMAddressCountyExt : PXCacheExtension<PMAddress>
    {
        public static bool IsActive() { return true; }
        #region UsrGetCounty
        [PXDBInt]
        [BaseIndexSelectorAttribute]
        public int? UsrGetCounty { get; set; }
        public abstract class usrGetCounty : BqlInt.Field<usrGetCounty> { }
        #endregion
    }
    public sealed class BaseIndexSelectorAttribute : AcctSubAttribute, IPXFieldSelectingSubscriber
    {
        public void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
        {
            if (e.Row is PMAddress)
            {
                sender.SetValue(e.Row, "UsrGetCounty", sender.GetValue(e.Row, "UsrCounty"));
            }
        }
        public override void RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
        {
            base.RowSelecting(sender, e);
            if (e.Row is PMAddress)
            {
                sender.SetValue(e.Row, "UsrGetCounty", sender.GetValue(e.Row, "UsrCounty"));
            }
        }
    }  

更改ContarctExt 扩展中UsrBaseIndex 字段的选择器的搜索类型,如下所示:

typeof(Search<PESKViewBaseIndex.priceIndexID, Where<PESKViewBaseIndex.recordID, IsNull, And<PESKViewBaseIndex.countyID, Equal<Current<PMAddressCountyExt.usrGetCounty>>, Or<PESKViewBaseIndex.countyID, IsNull>>>>)

【讨论】:

    猜你喜欢
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多