Adding new attachments via Customization?

Has anyone added an attachment to a document via a customization script? I know that the attachment file must first be “registered” in Epicor before being attached to the desired Epicor document. Via a trace, I learned that the required business object library for registering the attachment file is Ice.Contracts.BO.Attachment.DLL. Through trial and error, I discovered that the affiliated adapter object library is Ice.Lib.EpiClientLib.DLL, which contains the attachment logic. In the customization, I can create the adapter object and connect to the BO. But it won’t recognize any of the BO methods. I need the FileExists method that checks to see if the attachment file already is registered with Epicor (exists in Ice.XFileAttch) and the UploadFile method to write the information to Ice.XFileAttch if it doesn’t exist. The writing to the pseudo attachment tables in a document adapter dataset (InvcHeadAttch for the ARInvoice adapter for example) to link an existing Ice.XFileAttch reference in the various document entry and tracker UIs work fine.

The reason for this is we are trying to automate attaching UPS delivery receipts to the affiliated ShipHead, OrderHed and InvcHead records to help dispute invalid chargebacks by customers who claim merchandise wasn’t received in time or at all.

Any thoughts?

We do this, but via the “…Attch” parts of the individual adapters.

So, for example, in one I have to hand,

				Erp.Adapters.QuoteAdapter qAdapter = new Erp.Adapters.QuoteAdapter(oTrans);
				qAdapter.BOConnect();
				if (qAdapter.GetByID(quoteno))
				{
					if (qAdapter.GetNewQuoteHedAttch(quoteno))
					{
						Erp.BO.QuoteDataSet dsQuote = qAdapter.QuoteData;
						foreach (DataRow newrow in dsQuote.QuoteHedAttch.Rows)
						{
							if (newrow["RowMod"].ToString() == "A")
							{
								newrow["FileName"] = fto;
								newrow["DrawDesc"] = System.IO.Path.GetFileName(fto);
								break;
							}
						}
						qAdapter.Update();
					}
					else
					{
						System.IO.File.Delete(fto);
						MessageBox.Show("Failed to attach." + System.Environment.NewLine + fto);
					}
				}

Added:
I just noticed you said this part was working fine. The only other thing we do is to get the Epicor attachment file location from the company configuration data and use standard System code to move the file there before calling the above. We have never used any other BO than the ones in the individual adapters. In actual fact, it doesn’t even seem to matter if the file is in the normal location as long as it’s accessible to Epicor and the relevant users - we do some very particular files in a different location altogether.

1 Like

When I tried with just the adapter code, I couldn’t get it to recognize the DocumentType. This particular document we want to not be a link and also to save the docs in a different path. It kept attaching based on the default settings in Company Maintenance. I have been making various changes to the code along the way and may have it behaving differently than when I first tried to attach. I will try again to just use the adapter code, and see what happens and post here. Thanks.

For reference, here is the snippet of code that attaches the delivery notice PDF to the invoice, if the shipment has been invoiced.

					if (_invoiceNum != 0)
					{
						adInvoice.GetNewInvcHeadAttch(_invoiceNum);
						DataSet dsInvoice = adInvoice.ARInvoiceData;
						DataRow rAttch = dsInvoice.Tables["InvcHeadAttch"].Rows[0];
						rAttch["DocTypeID"] = "POD";
						rAttch["Company"] = edvCallContextClientData.dataView[edvCallContextClientData.Row]["CurrentCompany"].ToString();
						rAttch["InvoiceNum"] = _invoiceNum;
						rAttch["DrawDesc"] = "UPS " + _trackingNum;
						rAttch["FileName"] = @"\\derp-usap02\EpicorData\DEV\Inbound\PNY01\POD\" + _prefix + _trackingNum + ".PDF";
						adInvoice.Update();
					}

Out of interest, are you moving the file separately?

No, letting the system do it based on the settings in the document file type.

That’s probably the difference to our case, then. We put the file where we want it and pass the path.

I know you can do it all via BO because I’ve seen someone say so on here, but we’ve never needed to.

Got it working. Was missing the GetByID method before creating the Attachment record.

Thanks for the help.

1 Like

Hi Guys, I need one help. I am new to epicor. whether this can be done through BPM?

Whenever the PO is created either using Buyer Workbench or Purchase Oder Entry these 2 document (GTC & STC) should be automatically attached.

I have read through your conversations and tried in customization code it is working fine. but it will not affect both the screens. So Now I want the same concept should work through BPM. please share some sample BPM code for this. Any help is highly appreciated. Thanks in advance.

if that is not possible through BPM. I want to know the reason behind this.

If you were able to achieve the action in customization C# code, you should be able to duplicate it in a Pre-Processing Method Directive for PO.Update with a custom code object. The trigger conditions would be if ttPOHeader has an added row and the CallContextClient AssemblyName equals the Buyer Workbench or PO Entry DLL names.

1 Like