Solved

Trying to Attach a File to Setup Screen

  • 18 January 2024
  • 4 replies
  • 57 views

Userlevel 2
Badge

I am trying to email a file created in a process screen.  The file must first be attached to a record before I can send it.  I am trying to attach it to a setup screen in the module we added for this process and the code runs just fine, there is no error but the attachment is never put on the email. Also when I look at the records for UploadFile and UploadFileRevision  the Primary screen is null.  Also adding the file did not make the file option on the menu show.  

This is the code to upload the file (runs without error but nothing happens, email created and no attachement): 

byte[] filebytes = Encoding.ASCII.GetBytes(fileContent.ToString()); ;
FileInfo myFileInfo = new FileInfo(Guid.NewGuid(), operation.Trim() + ".txt", null, filebytes);
UploadFileMaintenance fileUploadGraph = PXGraph.CreateInstance<UploadFileMaintenance>();
fileUploadGraph.SaveFile(myFileInfo, FileExistsAction.CreateVersion);
PXNoteAttribute.AttachFile(this.Caches[typeof(JMSetup)], Setup.Current, myFileInfo);
//PXNoteAttribute.AttachFile(base.Caches[typeof(JMSetup)], Setup.Current, myFileInfo);
fileUploadGraph.Persist();
return myFileInfo.UID;

My question is can a setup screen have a file added to its record?  Also how to get the File Menu on the setup screen?  Does it need to have a note?  I noticed most setup screens don’t have note ids and they also don’t have a file menu.   

 

icon

Best answer by edwardmcgovern53 19 January 2024, 03:16

View original

4 replies

Userlevel 4
Badge +2

I think you might be using the wrong command.  It looks like you are adding a note to the page and not a file.  Try something like this

if (upload.SaveFile(info, FileExistsAction.CreateVersion))
{
    //Create connection to the Batch
    PXNoteAttribute.SetFileNotes(myCache, Document, info.UID.Value);  
}

Userlevel 2
Badge

Thanks for the response.  My coworker pointed out the SetFileNotes Method.  I already tried that and the same exact results.  Everything runs no error but the file uploaded is not associated with the setup record and of course its not attached to the email

Userlevel 2
Badge

Update I got the file attachment to work! with the sequence below I was not persisting (this.Persist()) in the current graph, only the file upload.  Seems minor but made a big difference.  I think one of the changes wasn’t getting completely saved because of it. 

 

byte[] filebytes = Encoding.ASCII.GetBytes(fileContent.ToString()); 
FileInfo myFileInfo = new FileInfo(Guid.NewGuid(), operation.Trim() + ".txt", null, filebytes);
UploadFileMaintenance fileUploadGraph = PXGraph.CreateInstance<UploadFileMaintenance>();
fileUploadGraph.SaveFile(myFileInfo, FileExistsAction.CreateVersion);                 
PXNoteAttribute.SetFileNotes(cache, data, (Guid)myFileInfo.UID.Value);
fileUploadGraph.Persist();
this.Persist();

 

 

Userlevel 7
Badge

Thank you for sharing your solution with the community @edwardmcgovern53!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved