首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在文档发布后创建额外的日志条目?

如何在文档发布后创建额外的日志条目?
EN

Stack Overflow用户
提问于 2018-05-25 17:09:49
回答 1查看 236关注 0票数 0

我想在一个文档Cash成功发布之后创建第二个日记条目。我试着用多种方法来解决这个问题,但总是遇到不同的问题。

在发布时创建的原始日志条目之后,我必须将创建此日志条目的代码放在哪里?在我的代码中,我需要的一些要求是原始批处理所使用的屏幕以及原始文档的参考编号。如果我能够获得第一批和它的GLTran记录,这将足够我创造新的记录。

请注意,Cash并不是唯一用于此操作的文档,因此,如果有一种方法来集中执行,这是一个加号,但不是必需的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-25 18:21:13

我为CashSale编写了这个示例。我相信它是足够通用的,您也可以将它应用到其他场景中。

在ARCashSaleEntry上创建一个图形扩展并重写发布操作:

下面是图扩展的代码,在代码注释中有解释:

代码语言:javascript
复制
using PX.Data;
using PX.Objects.GL;
using System.Collections;
using ARCashSale = PX.Objects.AR.Standalone.ARCashSale;

namespace PX.Objects.AR
{
    public class ARCashSaleEntry_Extension : PXGraphExtension<ARCashSaleEntry>
    {
        #region Event Handlers

        public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);

        [PXOverride]
        public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
        {
            // Get reference to current cash sale if required
            ARCashSale cashSale = Base.Document.Current;

            // Declare event handler so we can remove the named delegate
            PXGraph.InstanceCreatedDelegate<JournalEntry> instanceCreatedHandler = null;

            // Handler definition used to intercept Journal Entry Graph
            instanceCreatedHandler = delegate (JournalEntry oldJournalEntry)
            {
                // Remove event handler
                PXGraph.InstanceCreated.RemoveHandler<JournalEntry>(instanceCreatedHandler);

                // Add hook to intercept Batch persisted event
                oldJournalEntry.RowPersisted.AddHandler<Batch>(delegate (PXCache sender, PXRowPersistedEventArgs e)
                {
                    // Get reference to old batch 
                    Batch oldBatch = oldJournalEntry.BatchModule.Current;

                    // After oldBatch is inserted
                    if (oldBatch != null && e.Operation == PXDBOperation.Insert && e.TranStatus == PXTranStatus.Completed)
                    {
                        // Create new Journal Entry Graph
                        JournalEntry newJournalEntry = PXGraph.CreateInstance<JournalEntry>();

                        // Create new batch
                        Batch newBatch = new Batch();

                        // Set new batch properties here and insert it
                        newJournalEntry.BatchModule.Insert(newBatch);

                        // Iterate on old tran from old batch
                        foreach (GLTran oldTran in oldJournalEntry.GLTranModuleBatNbr.Select())
                        {
                            // Create new tran
                            GLTran newTran = new GLTran();

                            // Set new tran properties here and insert it
                            newJournalEntry.GLTranModuleBatNbr.Insert(newTran);
                        }

                        // Save new journal
                        newJournalEntry.Save.Press();
                    }
                });
            };

            // Add hook to intercept Journal Entry Graph
            PXGraph.InstanceCreated.AddHandler<JournalEntry>(instanceCreatedHandler);

            // Call base method to release document
            // Your hook will be called after this action in the context of a PXLongOperation
            return baseMethod(adapter);
        }

        #endregion
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50533995

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档