附件从VendorMaint图表添加时覆盖现有内容

时间:2015-05-12 11:26:04

标签: acumatica

我正在将第三方应用程序中的数据和文档导入Acumatica。

导入后,我使用下面的代码和附件动态创建供应商。

VendorMaint graph = PXGraph.CreateInstance<VendorMaint>();
VendorR row1 = null;
row1 = new VendorR();
row1.AcctName = VendorName;
row1.NoteID = noteid;      // Existing - GUID created while importing
graph.BAccount.Update(row1);

如果附件已经存在,那么它应该更新而不是重复。

在这种情况下,如果供应商已经存在附加文件,那么我的代码会覆盖这些附件并删除附加到该现有供应商的所有先前文件。

我想添加附件而不是覆盖现有附件。有什么建议吗?

2 个答案:

答案 0 :(得分:0)

尝试使用视图的插入方法:

VendorMaint graph = PXGraph.CreateInstance<VendorMaint>();
var row1 = new VendorR();
row1 = graph.BAccount.Insert(row1);
if (row1 == null) // already inserted or wasn't able to insert
{
      //some logic with newly created vendor
}
else
{
      //some logic with existed
}
row1.AcctName = "vendor name";
row1.NoteID = noteid;      // Existing - GUID created while importing
graph.BAccount.Update(row1);

答案 1 :(得分:0)

我找到了问题的解决方案。下面的代码有助于创建新附件,并且不会覆盖现有供应商的任何现有附件。

 // Getting the FileID of the attached file from DACClass
 UploadFile uf = PXSelectJoin<UploadFile,
    InnerJoin<NoteDoc, On<NoteDoc.fileID, Equal<UploadFile.fileID>>,
    InnerJoin<DACClass, On<DACClass.noteID, Equal<NoteDoc.noteID>>>>, 
    Where<DACClass.noteID, Equal<Required<DACClass.noteID>>>>.Select(this, noteid);

 if (uf != null)
 {
      PXNoteAttribute.SetFileNotes(graph.BAccount.Cache, graph.BAccount.Current, uf.FileID.Value);

      NoteDoc doc = new NoteDoc();
      doc.NoteID = uf.FileID.Value;
      doc.FileID = new Guid();
      graph.BAccount.Cache.Insert(doc);
 }