How to do auto attachment via BPM?

Whenever the PO is created either using Buyer Workbench or Purchase Oder Entry , two document should be automatically attached. any codes please share.I am new to epicor. dont know how to proceed

I have just created overview in bpm under "Ice.Attachment.UploadFile"

var POHeaderDet = (from r in Db.POHeader select r).FirstOrDefault();
  int intPONum = Convert.ToInt32(POHeaderDet["PONum"]);
  var SysCompany=(from SysCompany_row in Db.SysCompany where SysCompany_row.Company==Session.CompanyID select SysCompany_row).FirstOrDefault();
  if(SysCompany !=null)
    string fileloc = SysCompany.AttachNetworkRoot;
    string filename = @"\Sample.JPG";
   docTypeID = "samp";
   parentTable = "POHeader";
   fileName= fileloc + filename;

   // data="";

Attachments in Epicor is a 2 step process. 1) upload the file to Epicor 2) attach it to the record (PO, Job etc). if you are going to attach the same document(s) each time then you probably only need to upload it once. Then link the same uploaded file to each new PO.

Note: there are a few different ways (See company Maintenance -> Attachments) Epicor stores uploaded files too so the process will depend on which method your system is using.

I would also consider triggering this action from a method directive on PO business object / GetNewPOHeader method.

Alternative approaches.

  • Put the files in a shared folder somewhere and add a link to that folder on the PO entry screen via a customisation.
  • We have a customisation that creates a PDF of the PO, opens a new email and attaches the PO PDF along with our terms and conditions and leaves the email open for the purchsing staff to edit / send.


1 Like

This is the code I use for quickly attaching something from BPM land. I used a Func becuse I was doing multiple attachments, but maybe someday we’ll have global functions we can just call on like our own widgets… achem @Bart_Elia hint hint

Mine pulls from a UNC directory for it’s reference, but if you want to write standard Csharp to move the file or instead use the BOs and the attachment type for that you can do that as well.

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();
    xref.Company = callContextClient.CurrentCompany;
    xref.XFileName = $@"\\server\path\{iFilename}";
    xref.XFileDesc = iFilename;
    xref.DocTypeID = "CUSTOGPO";
    // Attach the file to the record
    XFileAttch xfile = new XFileAttch();
    xfile.Company = callContextClient.CurrentCompany;
    xfile.RelatedToSchemaName = "Erp";
    xfile.RelatedToFile = iRelatedTable;
    xfile.Key1 = iKey1.ToString();
    xfile.ForeignSysRowID = iRelatedGuid;
    xfile.XFileRefNum = xref.XFileRefNum;
    // Store the new attachment number for a rainy day
    outAttchNum = xfile.AttachNum;    
  return outAttchNum;
int attchnum = AttachFile(ud11.Key2, std.OrderHed[0].SysRowID, "OrderHed", std.OrderHed[0].OrderNum.ToString());

Thank you very much for your time . suggesting me good ideas . It works like a charm. I completed through PO business object GetNewPOHeaderAttach

Great! Thank you very much. its highly helpful to get through syntax. Once again thank you very much for the time in sharing info.

Hi Brett, Priya,
Any one can help me please?
I am also new to Epicor. Even I am looking for the kind of similar option. I created the printing routing rules for Auto-emailing the PO to suppliers.
But the requirement is need to keep the email left open for editing. Please provide me BPM steps to do it.

I just answered a similar question here.


@jgiese.wci you save this as a .cs file on a server then reference it in your BPM? How are you referencing this, or is this compiled into a dll?

It is written directly in a BPM nothing external

1 Like

It’s a Func or Action I can’t remember which, but those act sort of as callable methods within a method. Not ideal over something more global, but it works when your scope is limited to a single BPM and you need to call the same code a few times/ways.

1 Like