Skip to main content
Answer

Get files dialog 'Comments'

  • January 27, 2022
  • 3 replies
  • 72 views

darylbowman
Captain II
Forum|alt.badge.img+15

How can I programmatically get the ‘Comments’ of a file attached to an entity.

 

I’ve tried several different ways but the ‘Comments’ field always returns empty.

 

I can get the files with the following code:

UploadFileMaintenance uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
var files = PXNoteAttribute.GetFileNotes(Base.Message.Cache, email);

I tried this to get the comment:

string comment = uploadFileMaintenance.GetFileComment(file.Name) ?? string.Empty;

Also this:

string comment = file.Comment ?? string.Empty;

 

Nothing seems to work.

Best answer by jinin

Hi @Deetz 

Can you please try like below? 

Guid fileId = doc.FileID.Value;
 var result = (PXResult<UploadFile, UploadFileRevisionNoData>)GetFileByID(sender.Graph).SelectSingle(fileId);
                            UploadFile file = (UploadFile)result;
                            UploadFileRevision fileRev = (UploadFileRevision)result;
                            if (file != null && fileRev != null && !string.IsNullOrEmpty(file.Name))
                            {
                                
                                string comment = fileRev.Comment != null ? TextUtils.EscapeString(fileRev.Comment, '@', '$') : string.Empty;
                                
                            }

3 replies

jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • Answer
  • January 27, 2022

Hi @Deetz 

Can you please try like below? 

Guid fileId = doc.FileID.Value;
 var result = (PXResult<UploadFile, UploadFileRevisionNoData>)GetFileByID(sender.Graph).SelectSingle(fileId);
                            UploadFile file = (UploadFile)result;
                            UploadFileRevision fileRev = (UploadFileRevision)result;
                            if (file != null && fileRev != null && !string.IsNullOrEmpty(file.Name))
                            {
                                
                                string comment = fileRev.Comment != null ? TextUtils.EscapeString(fileRev.Comment, '@', '$') : string.Empty;
                                
                            }


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • January 27, 2022

@jinin - Where does ‘GetFileByID’ come from?


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • January 27, 2022

I just wrote a BQL select on those two tables in a fashion similar to what I assume that custom method did, and I got it to work. Thank you!