Skip to main content

Hello, the following code works in version 22.215.0056 but it doesn’t work in version 23.105.0016

UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();
NoteDoc doc = upload.Select<NoteDoc>().First(x => x.NoteID == fromNoteID);
if (doc == null) return; //no file attached - exit
Guid g = ToGuid(doc.FileID); //this just converts guid? to guid
PX.SM.FileInfo sourceFile = upload.GetFile(g);

In the older version upload.the GetFile method works and returns the details of the file to the sourceFile variable. In the new version the GetFile method always returns null. 

I’ve checked the guid and the file I would like to access does exist in the UploadFile table. Is there a new way to access files in the newer versions for Acumatica?

Thanks
Steve

Hi @stephenward03,

Instead of doing a Select to get the FileID you can use PXNoteAttribute.GetFileNotes to get the list of Guid of the files attached to the document.

Also, from my testing I see GetFile get the file info as expected. Below is the screens of the debug information,

 

 

Following is the graph extension used for testing, 

    public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
{
#region Event Handlers
public PXAction<SOOrder> getFileTest;
PXUIField(DisplayName = "GetFileTest")]
PXButton]
protected IEnumerable GetFileTest(PXAdapter adapter)
{
UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();
Guid ] g = PXNoteAttribute.GetFileNotes(Base.Document.Cache, Base.Document.Current);
foreach (Guid item in g)
{
PX.SM.FileInfo sourceFile = upload.GetFile(item);
}
return adapter.Get();
}
#endregion
}

You can debug to see what is happening when you hit GetFile. Please feel free to post back to you have any question.! Happy Coding.!


Thanks for your comments @Vignesh Ponnusamy 

I used the graph extension you provided and it worked on my system. 

In my case, I want to use select and not PXNoteAttribute.GetFileNotes so I adjusted the code and tried again. upload.GetFile() returns the file details as expected from a button on sales orders. Which is great. See below.

 

However, if I try the same code from an override of ReleaseDocProc, then GetFile() still returns null. See below, ‘sourceFile‘ in the watch window is null. 

So the problem might be linked to where I’m using the GetFile() method and not the syntax. 

I’ve added my code below, would you be able to try this on your system please and let me know if you get the same results (you’ll need to update the RefNbr value), and how to work around this problem. 

public class ARReleaseProcess_Extension : PXGraphExtension<PX.Objects.AR.ARReleaseProcess>
{
public static bool IsActive() => true;

public delegate List<ARRegister> ReleaseDocProcDelegate(JournalEntry je, ARRegister ardoc, List<Batch> pmBatchList, ARDocumentRelease.ARMassProcessReleaseTransactionScopeDelegate onreleasecomplete);
ePXOverride]
public List<ARRegister> ReleaseDocProc(JournalEntry je, ARRegister ardoc, List<Batch> pmBatchList, ARDocumentRelease.ARMassProcessReleaseTransactionScopeDelegate onreleasecomplete, ReleaseDocProcDelegate baseMethod)
{
UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();
ARRegister aRRegister = upload.Select<ARRegister>().First(x => x.DocType == "INV" && x.RefNbr == "003975");
NoteDoc doc = upload.Select<NoteDoc>().First(x => x.NoteID == aRRegister.NoteID);
PX.SM.FileInfo sourceFile = upload.GetFile((Guid)doc.FileID);

List<ARRegister> arReg = baseMethod(je, ardoc, pmBatchList, onreleasecomplete);

return arReg;
}
}

Above is the ARReleaseProcess code - sourceFile is always null with this code.

public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
{

public static bool IsActive() => true;

public PXAction<SOOrder> GetFileTest;
ePXUIField(DisplayName = "GetFileTest")]
FPXButton(CommitChanges = true, DisplayOnMainToolbar = true)]

protected IEnumerable getFileTest(PXAdapter adapter)
{
UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();
ARRegister aRRegister = upload.Select<ARRegister>().First(x => x.DocType == "INV" && x.RefNbr == "003975");
NoteDoc doc = upload.Select<NoteDoc>().First(x => x.NoteID == aRRegister.NoteID);
PX.SM.FileInfo sourceFile = upload.GetFile((Guid)doc.FileID);
return adapter.Get();
}

}

Above is the SOOrderEntry extension - sourceFile works fine with this code.

Thanks

Steve

 

 


Hi @Vignesh Ponnusamy 

I’ve been digging deeper into the source code using dnSpy. After checking a few things I updated the SQL record for my file to change the field ‘IsPublic’ from 0 to 1. 

After making this change the code works! When I call GetFile() in ARReleaseProcess the file information is returned to my sourceFile variable. 

I’m not sure why changing this field has worked, or what the IsPublic field is supposed to control. I’m creating the files in the first place so hopefully I will be able to set the file to be Public and then I’ll have access to it. Not sure.

Do you know more about this field? 


Hi @stephenward03,

Thanks for sharing the interesting information.

In the File Maintenance(SM202510) screen, I see Is Public check box. And looks like the purpose of the check box is to allow all the user to access the file. Ignoring the access rights information,

 

There are also information in the documentation(about the field) that could help you, https://help.acumatica.com/(W(197))/Help?ScreenId=ShowWiki&pageid=cedc116f-1c35-4053-9aae-65a525be642f 

Good Luck.!

 


Reply