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();
if(POHeaderDet!=null)
  {
  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="";
    //result
    }
  }

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.

Brett

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();
    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());
7 Likes

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.
Thanks
Subha

I just answered a similar question here. https://www.epiusers.help/t/is-there-any-way-to-edit-the-email-content-before-autoemailing-the-po-through-ssrs-routing/58947/9

Brett

@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