How To Attach Documents to Related Tables

It took me a while to get to the final solution, but I got there!

The business reason behind this solution is wanting to automatically attach certificates that get attached to the Receipt Line to the Part Lot record. If you have requirements that you need to track certifications for your parts, either for internal and/or customer need, this takes the attachments added at receipt and attaches them to the Part Lot in the background. By doing this, it will be easier for users to get to the documentation by just going through Lot Tracker. Otherwise, they would have to go to Lot Tracker, find the receipt record, and then go to the receipt to get the document. This will also facilitate the ability to create a customization to gather all documentation for a Job by looping through the parts, seeing if they are lot tracked, and then checking the PartLot for the document. That will be my next step, building an APR that grabs all of the documents and prints/emails them out.

The first step is to create Document Types for whatever repository you are using with Document Type Maintenance. I am using ECM, but this should work for anything. I created a document type with a Certs ID. I also flagged it as Reserved for Specific Tables and required for Receipt and Shipment.

Next is to create the specific table control using Document Type Control Maintenance. Here you select the Table and Document Type. Also select Expose in Tree (it does not work in the web, but I am hoping Epicor fixes that). You want to do this for the PartLot and RcvDtl tables.

Next you want to select the Metadata to associate with the Document Type. Here is what I selected. This helps with searching for documents where they are stored (if it supports the transfer of the metadata).

image

Now that the document controls are set up, you can start creating the customization. First is a Standard Data Directive on XFileAttach. You want to trigger your customization when the document is successfully attached in the DB. Interesting thing to note here, documents are processed one at a time. Even if you add multiple attachments at once, each document goes through by itself and not in a group. Here is the workflow and variables.

image

image

  • Start with a Condition checking that there is an added row in the table.
  • Next are two Set Variable to take the ForeignSysRowID and XFileRefNum so you can pass them to a Function.
  • The first Invoke Function is to get the Document Type. I left this as a separate function as this can be used for other instances where you need to duplicate an attachment.
    image
  • The second Function is to attach the document to the other table.
    image

Now I will detail the Functions.

GetDocType is just like it sounds, it gets the Document Type because it is not available in the XFileAttach table. It is a Custom Code block with the following in it.

string xDocType = Db.XFileRef.Where(x => x.XFileRefNum == refNum)
                          .Select(x => x.DocTypeID).FirstOrDefault();

if (xDocType != null)
{
  docType = xDocType;
}

string xFileName = Db.XFileRef.Where(x => x.XFileRefNum == refNum)
                          .Select(x => x.XFileName).FirstOrDefault();

if (xFileName != null)
{
  fileName = xFileName;
}

refNum2 = refNum;

The other Function is AttachCertsPartLot, that does as it sounds. There are some BO calls to get data and then uses the data to call the PartLot Attach method and Update method to save it.

  • First is a BO call of RcvDtlSearch.GetBySysRowID where you use the ForeignSysRowID from earlier to get the row for the PartNum and LotNum.
  • Next is a condition to check that the LotNum field is populated and that the DocType is Certs.
  • Another BO call of LotSelectUpdate.GetNewPartLotAttach to get the LotSelectUpdateTableset with the PartNum and LotNum.
  • The next 3 blocks set fields in the tableset. First is RowMod = A, next is to set the FileName, and last is the DocTypeID.
  • Now that you have added the data to the tableset, you can run the Update method to finish it off.

Done. Attachment now lives in both tables. Let me know if you have any questions.

Here are some posts that I did in trying to get to my final solution. My issue was that we own ECM but do not own either of the Integration Modules, so I could not do it in ECM like I originally wanted to. I did figure out how to reach the ECM API, but thought it would be too much work trying to build the integration myself.

8 Likes

Happy Lord Of The Rings GIF

4 Likes

So the only 1 file is stored? what about it is deleted from one place?

1 Like

It creates 2 XFileAttch records based off of one XFileRef record. I did some querying of the tables to see how Epicor handles duplicating of attachments (e.g. ECOMtl to JobMtl). I saw that it was only one XFileRef and went with that approach.

You bring up a very good point. I will have to test what happens when I delete one of them. I may have to build a delete Function to handle it.

@Olga , have you ever read the documentation on the XFileAttch table in Data Dictionary? Can you confirm if that functionality exists as detailed? Or was it just a future feature that never made it?

To save everyone from finding it, here is what I am referencing.
image

DupToRelatedToFile - In some cases the system will duplicate a XFileAttch attaching it to a different table. Ex: RcvDtl attachments may be replicated to PartLot. When this duplication occurs the source XFileAttch record ?DupTo? fields are updated and provide a link between the two. If the source XFileAttch is changed or deleted so will the record that was duplicated.

DoTrigger - A flag used to force a write trigger event even though none of the other fields are changing. FYI: Originally created to handle the automatic duplication of RcvDtl attachments to the PartLot. If Part or LotNum is changed in RcvDtl or the DocType is changed the related XFileAttch.DoTrigger will be set to Yes. Which will then invoke the logic which automatically syncs up PartLot Attachments. Note DocType change sets this flag only the single specific XFileAttch record. It does not invoke the triggers for other XFileAttch records that are be related to the same XFileRef

2 Likes

I was just reading that - it sounds like it’ll do exactly what you’re trying to do.

Yes, but there is no trigger for what are related attachments. And the attach method does not have any of those fields in it.

I read it the ‘other’ way - if you set the trigger and other fields it would duplicate the entry. Sounds like it’s the opposite - which is of no help.

I wonder if there is there something on Part/Lot/PartLot setup in Company/Site
Configuration/Maintenance to cause these field to be set and ‘trigger’ the duplication.

If you find it, let me know!! I could not find anything.

1 Like

I just tested deleting the attachment from RcvDtl and it stayed on the PartLot. I will have to create a function that checks if a file is deleted and then search for any other references. That is easy, but I don’t know how I will handle changes yet.

3 Likes

Looked for a while and cannot find any reference to the functionality described in the Help.

Just thinking out loud - if Olga doesn’t confirm the functionality exists for those Dictionary descriptions, and since you are halfway there, maybe you can complete the Function library and BPMs that will use those fields to do the user-defined document ‘duplication’ and removal functions. You know, as a side project in your free time :slight_smile:

I was thinking of going down that route, but since I did not know if there was any Epicor defined functionality, I chose to just do it myself. I guess I could de-compile some of the dlls involved and see if there is anything to use, but that seems like it would be a lot.

1 Like

John, the work you’ve done is great, but would you mind stepping back a bit and giving us an ELI5 of exactly what you are trying to do. (Not another tech filled graphic, but more a step by step with the business use case.)

Just when I think I get it, I get confused again.

:people_hugging:

Always.

If you work at a company that uses raw metal in their manufacturing process, you generally need to track HEAT numbers. A HEAT number is basically a lot number, it gets assigned to the metal during the manufacturing process and ties it to a material certification (mill test) that states the material is what you actually ordered. When you order sheet metal from a supplier, they provide you with the HEAT number and the mill test certificate. As a manufacturer, you receive the material in and attach the documentation to the receipt line. You also internally lot track it so you know what documentation is associated with them.

99.9999999% of your customers require the mill test certificates and HEAT number for the product you are manufacturing for them. At time of shipment, you need to gather those documents and print hard copies or email to them.

This is where my solution comes in. Many manufacturers just store the certificates on a shared drive and do a half-:donkey: job of actually tracking the metal in their four walls. This mainly has to do with a bunch of old-timers who “always did it that way” and never updated their processes to incorporate new technology. The number of workarounds I have seen to track metal in my career is astounding. On a side note, I would never trust a metal manufacturer’s documentation without auditing them.

If you lot track your metal parts and attach the documentation to the receipt line, you now have the documentation easily available. But, you have to find the job that the part was manufactured on, go to the material transactions on the job to find the lot number, open up lot tracker, find the PO that is related to the lot, open up PO Tracker, find the related receipt, open up receipt tracker, and finally get the attachment. Lots of clicks.

So, instead of only having the documents on the receipt, it would be nice if the system auto attached the documentation to the Part Lot table too. That way a user can easily get to it from the Job by opening Lot Tracker. It also makes it easier to build an APR to gather all of the related documents because all you need is the Job and Lot to get to the documents.

Epicor now provides a Lot Trace screen, but it just cuts out opening the Lot Tracker, PO Tracker, and Receipt Tracker. Instead, you can open up the Lot Trace and then the Receipt Tracker, but it still does not attach it to the Part Lot. This is where the documents should really live, and to do that manually would require a lot of someone’s time.

At the end of the day, if you bought stainless steel 316 because you needed it’s specific properties for something and then get notified that it was really 304, it could potentially cause issues for the end user. Whether that is a plane, medical machine, or something else.

Could I build my own dashboard that took a Job Number as the input and bring back all of the related lot receipts? Sure, but someone would still need to gather the documents for shipping. I think I will be able to use an APR to do that at shipment instead. Have not created it yet, but I believe it is possible.

2 Likes

Excellent :people_hugging:

I have a couple of alternate ideas, but I’d like to here a little bit more.

On to your solution, could you explain simply where you want the files to live etc?

Ie, are you wanting one attachment, two refs etc.

I’ve got the need down, now I’m still a little confused on the process.

Just the overview needed.

Ideally, it should live on the Part Lot table. The receipt may have 20 pieces that gets used on 20 different jobs and 20 different shipments that you need the documentation for.

I’m sorry if I’m being dense or not explaining what I want well.

Step by step explain what you want to happen.

I’m not following.

No worries.

I want exactly what my customization is doing. When a document is attached to a receipt line, if the part is lot tracked, attach the documentation to the Part Lot.

I do need to create something for updates/deletes of the document attached to the receipt.

2 Likes

I ran into this EXACT scenario at an implementation last year. We didn’t get this in place prior to going live, and I don’t know if they’ve gone any further on it. They also had ECM, which makes it easier for APR to include documents. I will watch this thread with bated breath…

1 Like

I do, and this is EXACTLY our issue as well, which is why I was interested. Just didn’t realize you and I are in the same line of work :wink:

This is perfect - single instance storage of the actual document, but multiple links to any Lots(Heat#'s) that are associated with it.

To be clear, your solution requires the receipt transaction and lot creation to occur before the document is attached, right?

And then I thought, if you were to use ECM to store the attachment, you could effectively cause the duplication for each lot to occur using the workflow tools.

1 Like