Control where Attachment is uploaded when using Ice.BO.AttachmentSvc UploadFile() method

Hey All,

I’ve been trying to use the REST API to Upload a PDF file to our server, and then attach it to a specific quote.

I’m familiar with the steps of the process; I’m just having troubles with figuring out how the UploadFile() method is actually pushing the file to the server.

I would like to know what exactly the “parentTable” field is in the UploadFile() method of the Ice.BO.AttachmentSvc.

If I leave both docTypeID & parentTable fields empty, the response body returns this:
{
“returnObj”: “SSW\Shukla_Jan 2020 Commissionsss.pdf”
}

SSW is a subfolder within \erp-app\EpicorData\Companies. When checking that folder, no PDFs exist. I’m not sure if that pertains to the returnObj that comes back from the UploadFile() method.

Any help with this would be greatly appreciated!

The only control you have over where the file is uploaded is the directory shown in Company Maintenance. Under that directory, the folder structure is fixed. {base}\"some string like attach"\{company ID}\{table name}\{ file name}. This is the default behavior for the File System, SharePoint, and DocStar attachment types.

The only way I know to have total control of the file location is to use the File Attachment Link and specify the fully qualified path if using an SMB share or a hyper link for SharePoint or DocStar document.

:man_shrugging:

do you actually upload file by specifying binary data in .data field?
in POST Ice.BO.AttachmentSvc/UploadFile:
{
“docTypeID”: “string”,
“parentTable”: “string”,
“fileName”: “string”,
"data": "string"
}

It can be base64 string of your binary file.

Hey @Olga,

I first tried passing the file binary for the “data” field, but it didn’t like it. However, I had success passing the file as a base64.

After getting a successful response back from the UploadFile() method, I am able use the FileExists() method within Ice.BO.AttachmentSvc, to which I get a true value in the response if using the correct fileName, parentTable, docTypeID. But when I search for the file on the server, it can’t be found anywhere.

Otherwise, I have the rest of the process down. I am able to get the attachment to show up in the Opportunity/Quote Entry dashboard by passing the correct values in both the XFileRef() method and the QuoteHedAttaches() method in the Erp.BO.QuoteSvc service.

Only when going to view it, it first asks what app do I want to use to view it (on PDF attachments that can actually be viewed, Adobe AR auto opens). When selecting Adobe AR, it opens up to this:

Could it be that the file is simply hidden or locked?

I have also tried using a Document Type, and manipulating the Base URL to see if I could get a file to appear elsewhere, but still get the Company ID dumped in between what I pass as the Base URL, and then followed by the parentTable value (if I pass one), and then the file name (exactly as how @Mark_Wonsil explained).

If all else fails, SharePoint seems to be my potential saving grace.

Did you set specific folder for file attachments in company maintenance form?
Also is file transfer using service selected there in company maintenance form?

Yes, I tried a few things on that form, but was unsuccessful. However, I could have been doing something wrong. :man_shrugging:

I believe adding a value to the “Default base location” input (after checking “Enable file system”) acted similar to trying to manipulate the file location in the Document Type Maintenance forms’ Base URL field. It would still put the CompanyID (‘SSW’ in my case) after the base URL, and before the file name.

‘File Transfer Using Service’ is also selected for the File Transfer Mode.

maybe the account that is used for IIS application pool does not have access to the requested folder on the server?

So after a few goes at it, I was able to get the file uploaded to a folder I could find; I did however run into some roadblocks.

First off, I would like say thank you for all the quick responses! @Olga & @Mark_Wonsil, your suggestions definitely led me in the right direction.

Trying to manipulate where the UploadFile() method was as simple as using a Document Type. My first mistake was passing the wrong baseURL. I was trying to pass the server location e.g. \erp-app\EpicorData\Companies\SSW as the baseURL. I realized I was using the wrong file path when I used this:

It makes sense the actual drive letter in the file path works, given it’s on the application level.

Setting up a Document Type like this:

Allowed me to call the UploadFile() file in this manner with the expected results:
{
“docTypeID”: “QPDF”,
"parentTable": “<%-Customer Name-%>”,
“fileName”: “testingQuoteThiss.pdf”,
“data”:
}

I would also like to note that the parentTable does not have to match up with any table name within Epicor’s DB. This parentTable field just adds another file name (to the right of the baseURL) to the structure of the baseURL set in the Doc Type.

For general understanding of this whole post, this UploadFile() method is being used to allow a web app to use REST calls to take a submitted PDF (Purchase Order) and attach it to a quote. A problem arose if not using the parentTable field: all submitted PDFs will go to this path - D:\EpicorData\Companies\SSW\Attachments. What if two PDFs with the same file name were submitted by different customers? One file would be replaced and the other lost.

The end solution: passing the Customer Name from the data on the client side to the rest call, using that Customer Name for the parentTable field. Now a new folder is created for each Customer Name, adding another layer of folders based on Customer Name.

1 Like

There is FileExists method or similar

If you don;t use parent table, will you be able to retrieve that attachment from UI? Like in Sales Order etc

Hi bro,
I has working with the similar but Im new on this function, may I know is that possible to use C# format code to upload my local director file to Epicor server? for example at OrderHed attachment.

Thanks