Copy Order Entry Attachment to Job Header

Does anyone have the code for copying an Order Entry header attachment to Job Entry header table? At creation of a make to order demand link in Job Entry, we would like to look and see if there is an attachment on that order, then bring it to the Job Header via a BPM. Is this possible?
Thanks!

Attachments are stored in the table XFileRef. The attachments are linked to various forms through the XFileAttch table. The key fields define which form or table the attachments are linked to. Do some BAQ research with the tables first to see what the format of the data is like. Then you can create a BPM to duplicate a record on the XFileAttch table, changing only the reference keys. I haven’t tested this, but that should link up the attachments.
Good luck!
Nate

This helps get me started. I am not sure how to access the XFileAttch table from a JobEntry update BPM. The table is not listed in the update field widget.

@NateS

You can do a DB lookup on the existing attachment(s) during that BPM you are using and then create a new attachment with the same information as the original just a new RelatedToFile and Key set.

BufferCopy with excludes would work great for this.

This is what I have used in the past for creation of attachments. It’s more than what you need if you were to use BufferCopy to copy the order record and just alter the key fields. You would need to create a new attch record and then copy into that so it has the IDs and stuff you need.

Or you can use a version of below for your own purposes and that would work too.

Func<string, Guid, string, string, int> AttachFile = (iFilename, iRelatedGuid, iRelatedTable, iKey1) =>
{
  int outAttchNum = 0;
  using (var txscope = IceDataContext.CreateDefaultTransactionScope())
  {
    // Create the system file reference
    XFileRef xref = new XFileRef();
    Db.XFileRef.Insert(xref);
    xref.Company = callContextClient.CurrentCompany;
    xref.XFileName = $@"\\server\path\{iFilename}";
    xref.XFileDesc = iFilename;
    xref.DocTypeID = "CUSTOGPO";
    Db.Validate(xref);
      
    // Attach the file to the record
    XFileAttch xfile = new XFileAttch();
    Db.XFileAttch.Insert(xfile);
    xfile.Company = callContextClient.CurrentCompany;
    xfile.RelatedToSchemaName = "Erp";
    xfile.RelatedToFile = iRelatedTable;
    xfile.Key1 = iKey1.ToString();
    xfile.ForeignSysRowID = iRelatedGuid;
    xfile.XFileRefNum = xref.XFileRefNum;
    Db.Validate(xfile);
      
    // Store the new attachment number for a rainy day
    outAttchNum = xfile.AttachNum;    
    txscope.Complete();
  }
    
  return outAttchNum;
};
 
int attchnum = AttachFile(ud11.Key2, std.OrderHed[0].SysRowID, "OrderHed", std.OrderHed[0].OrderNum.ToString());
1 Like

This is an example of the buffer copy I was talking about. This is how I created a Copy User action in User Account Security Maintenance.

4 Likes

This seems like the path I am looking for…Would I be able to access the XFileAttch table using this? @jgiese.wci

Of course!