Import attachments

I am trying to import sales orders with attached documents. I have managed to import the sales orders and the document but cannot figure out how to link the documents as attachments to the sales orders on import.

The problem is that relatedId in DmsFile is not really a reference field, it is merely a number. I am using the following import config but of course it doesn’t work (relatedId remains null):

  <input file="dms_dmsFile.csv" separator=";" type="com.axelor.dms.db.DMSFile" search="self.importId = :importId">
     <bind to="relatedId" type="" search="self.saleOrderSeq = :relatedSaleOrderSeq"/>

How can I set relatedId to the correct value during import ?


Answering my own question:

It seems Axelor has certain requirement for DMS files to appear as attachments in one of the sales orders:

  • There needs to be one and only one DMS 2nd level directory per sales order under the top level « Sales Orders » DMS directory. This directory has to be linked (through relatedId) to the sales order.
  • The 2nd level directory filename should be the Id of the related sales order. Not sure if this is a requirement, but that is what Axelor does, so it is a good idea to follow that rule for consistency even if not strictly necessary.
  • Any DMS file linked to a sales order should have the one and only 2nd level directory related to the sales order as its ultimate parent. It does not have to be its direct parent.
  • It should go without saying but it is important that the correct mime type be set in MetaFile.fileType in order for the file to be handled properly by the front end (e.g. PDFs need to be marked as application/pdf so that the viewer is automatically loaded in the frontend).

Fulfilling these requirements during import from another system (not just loading demo data which can be arranged conveniently for easier import) using import xml configurations can be tricky but it’s doable.
Hope this helps anyone trying to