Acumatica 附件未显示在文档中

Acumatica 附件未显示在文档中,acumatica,Acumatica,我需要在保存采购订单时生成文件,以便上传到ftp,并在文件部分将文件作为附件保存为文本文件 我正在RowPersisted事件中生成文件 protected void POOrder_RowPersisted(PXCache cache, PXRowPersistedEventArgs e, PXRowPersisted InvokeBaseHandler) { if (InvokeBaseHandler != null) InvokeBaseHandler(cache,

我需要在保存采购订单时生成文件,以便上传到ftp,并在文件部分将文件作为附件保存为文本文件

我正在RowPersisted事件中生成文件

protected void POOrder_RowPersisted(PXCache cache, PXRowPersistedEventArgs e, PXRowPersisted InvokeBaseHandler)
{
    if (InvokeBaseHandler != null)
        InvokeBaseHandler(cache, e);
    var row = (POOrder)e.Row;
    if (e.TranStatus == PXTranStatus.Open)
    {
        if (row.Hold != true && row.Status == POOrderStatus.Open)
        {
            string output = GenerateFeed();  // Generates Feed and upload to Ftp.
            AttachFile(row, output);
        }
    }
}


private void  AttachFile(POOrder row , string output)
{
    string filename = $"{row.OrderNbr.ToString()}.txt";
    byte[] data = output.ToByteArray();
    PX.SM.UploadFileMaintenance filegraph = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
    PX.SM.FileInfo fileinfo = new PX.SM.FileInfo(filename, null, data);
    if (filegraph.SaveFile(fileinfo, PX.SM.FileExistsAction.CreateVersion))
    {
        PXNoteAttribute.SetFileNotes(Base.Document.Cache, row, new Guid[] { fileinfo.UID.Value });
        string note = PXNoteAttribute.GetNote(Base.Document.Cache, row);
        PXNoteAttribute.SetNote(Base.Document.Cache, row, note);
    }
}   
protectedvoid POOrder\u行持久化(PXCache缓存、PXRowPersistedEventArgs e、pxRowPersistedInvokeBaseHandler)
{
if(InvokeBaseHandler!=null)
InvokeBaseHandler(缓存,e);
var row=(POOrder)e.row;
如果(e.TranStatus==PXTranStatus.Open)
{
if(row.Hold!=true&&row.Status==POOrderStatus.Open)
{
字符串输出=GenerateFeed();//生成提要并上载到Ftp。
附件文件(行,输出);
}
}
}
私有void AttachFile(POOrder行,字符串输出)
{
字符串文件名=$“{row.OrderNbr.ToString()}.txt”;
字节[]数据=输出。ToByteArray();
PX.SM.UploadFileMaintenance filegraph=PXGraph.CreateInstance();
PX.SM.FileInfo FileInfo=新的PX.SM.FileInfo(文件名,null,数据);
if(filegraph.SaveFile(fileinfo,PX.SM.FileExistsAction.CreateVersion))
{
PXNoteAttribute.SetFileNotes(Base.Document.Cache,行,新Guid[]{fileinfo.UID.Value});
string note=PXNoteAttribute.GetNote(Base.Document.Cache,行);
PXNoteAttribute.SetNote(Base.Document.Cache,行,注释);
}
}   
附件在文档的“文件”菜单中不可用

检查后,我发现链接不是在NoteDoc中创建的


有人能解决这个问题吗

我认为问题在于,在POOrder行被持久化之后,修改它已经太迟了,因为它不会再次被持久化。您可能正确附加了文件,但在附加文件后未保存POOrder记录

您可以在RowPersisted中修改POOrder,但如果不导致无限循环,则无法再次将其持久化

您需要修改并持久化POOrder以附加文件,因此我建议挂起RowPersisting而不是RowPersisted:

void POOrder_RowPersisting(PXCache cache, 
                           PXRowPersistingEventArgs e, 
                           PXRowPersisting del)
这将解决保存问题,因为persisteng是在persistend实际将更改持久化为POOrder之前调用的。要附加文件,只需调用SetFileNotes:

if (filegraph.SaveFile(fileinfo, PX.SM.FileExistsAction.CreateVersion))
{
    PXNoteAttribute.SetFileNotes(Base.Document.Cache, row, fileinfo.UID.Value);
}

我已经覆盖了Persist和生成提要以及将文件附加到文档

我在这里遇到的一个问题是多次调用的方法,每次执行都会生成feed,并在文件系统中添加一个新版本

我通过在POOrder DAC上创建一个作为扩展名的无界字段来控制文件生成

public delegate Int32 PersistDelegate(Type cacheType, PXDBOperation operation);
    [PXOverride]
    public Int32 Persist(Type cacheType, PXDBOperation operation, PersistDelegate baseMethod)
    {
        var row = Base.Document.Current;
        POOrderExt ext = Base.Document.Cache.GetExtension<POOrderExt>(row);
        if (row.Hold != true && row.Status == POOrderStatus.Open && Base.Document.Cache.GetStatus(Base.Document.Current) != PXEntryStatus.Inserted)
        {
            if (ext.UsrIsProcessed == null && (operation == PXDBOperation.Delete || operation == PXDBOperation.Update))
            {
                ext.UsrIsProcessed = true;
                string output = GenerateFeed();
                AttachFile(row, output);
            }
        }

        return baseMethod(cacheType, operation);
    }
public委托Int32 PersistDelegate(类型cacheType,PXDBOperation操作);
[PXOverride]
public Int32 Persist(类型cacheType、PXDBOperation操作、PersistDelegate baseMethod)
{
var row=Base.Document.Current;
POOrderExt ext=Base.Document.Cache.GetExtension(行);
if(row.Hold!=true&&row.Status==POOrderStatus.Open&&Base.Document.Cache.GetStatus(Base.Document.Current)!=PXEntryStatus.Inserted)
{
if(ext.UsrIsProcessed==null&&(operation==PXDBOperation.Delete | | operation==PXDBOperation.Update))
{
ext.UsrIsProcessed=true;
字符串输出=GenerateFeed();
附件文件(行,输出);
}
}
返回baseMethod(缓存类型、操作);
}
DAC扩展

    public class POOrderExt : PXCacheExtension<POOrder>
    {
        #region UsrIsProcessed
        [PXBool]
        public virtual bool? UsrIsProcessed { get; set; }
        public abstract class usrIsProcessed : IBqlField { }
        #endregion
    }
公共类POOrderExt:PXCacheExtension
{
#已处理的区域
[PXBool]
公共虚拟bool?UsrIsProcessed{get;set;}
公共抽象类usrIsProcessed:IBqlField{}
#端区
}