我想在一个文档Cash成功发布之后创建第二个日记条目。我试着用多种方法来解决这个问题,但总是遇到不同的问题。
在发布时创建的原始日志条目之后,我必须将创建此日志条目的代码放在哪里?在我的代码中,我需要的一些要求是原始批处理所使用的屏幕以及原始文档的参考编号。如果我能够获得第一批和它的GLTran记录,这将足够我创造新的记录。
请注意,Cash并不是唯一用于此操作的文档,因此,如果有一种方法来集中执行,这是一个加号,但不是必需的。
发布于 2018-05-25 18:21:13
我为CashSale编写了这个示例。我相信它是足够通用的,您也可以将它应用到其他场景中。
在ARCashSaleEntry上创建一个图形扩展并重写发布操作:

下面是图扩展的代码,在代码注释中有解释:
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
}
}https://stackoverflow.com/questions/50533995
复制相似问题