微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从 Note Table 获取 DAC 记录

如何解决如何从 Note Table 获取 DAC 记录

当我不知道笔记附加到什么 dac 类型时,有没有人有关于如何从 RefNoteId => DAC 转到的代码片段?

我已经做到了这一点(row.RefNoteID 是我的起点)

        Note note = PXSelect<Note,Where<Note.noteID,Equal<required<Note.noteID>>>>.Select(this,row.RefNoteID);
        Type recordtype = Type.GetType(note.EntityType);
        PXCache recordCache = Caches[recordtype];  

我现在如何执行 PXSelect>>>.Select(GRAPH) ? recordtype 可以是系统中任何具有 noteID 的 DAC。

谢谢

解决方法

以下代码对我有用,它基于 Acumatica 在 PXRefNoteSelectorAttribute.PrimaryRow_RowPersisted 中获取记录的方式。

这种方法的问题在于,这将适用于 SOOrder、INRegister、SOInvoice、SOSshipment 等 Header 实体。但是对于像 SOLine、INTran 和其他“细节”实体,这种方法只有在相应的记录有一些与文本/文件相关的注释时才有效。 Acumatica 将与它们的 NoteID 相对应的记录添加到 Note 表中,前提是该详细记录有一些 Note/Text。我最好的猜测是这样做是为了避免过度发送 Note 表。

using PX.Data;
using PX.Objects.SO;
using System;
using System.Collections;
using System.Linq;
using System.Web.Compilation;

namespace SearchByNoteID
{
    // Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
    public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
    {
        public PXAction<SOOrder> searchByNoteID;

        [PXUIField(DisplayName ="Search by Note ID")]
        [PXButton(CommitChanges = true)]
        public virtual IEnumerable SearchByNoteID(PXAdapter adapter)
        {
            var order = adapter.Get<SOOrder>().FirstOrDefault();
            if(order!=null)
            {
                //
                //...
                //
                Guid? noteID = GetNoteID();
                object record = GetRecordByNoteID(noteID);
                //
                //... do whatever you want with the record
                //
            }
            return adapter.Get();
        }
        protected object GetRecordByNoteID(Guid? noteID)
        {
            var type = GetEntityType(this.Base,noteID);
            if(type==null) return null;
            object entityRow = new EntityHelper(this.Base).GetEntityRow(type,noteID);
            return entityRow;
        }
        protected Type GetEntityType(PXGraph graph,Guid? noteID)
        {
            if (noteID == null)
            {
                return null;
            }
            Note note = PXSelectBase<Note,PXSelect<Note,Where<Note.noteID,Equal<Required<Note.noteID>>>>.Config>.SelectWindowed(graph,1,new object[]
            {
                noteID
            });
            if (note == null || string.IsNullOrEmpty(note.EntityType))
            {
                return null;
            }
            return PXBuildManager.GetType(note.EntityType,false);
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。