Improvements in Attachment model in Openbravo

Attachments are one of the breezy UI aspects of Openbravo, where you can attach any number of attachments to any record in the application. The beauty of the feature lies in the fact that you can restrict the access to the attachments for a specific users/roles. An use case is provided here. From 3.0MP26 there are some improvements in the way Attachments are implemented. 

Change in architecture

Before 3.0MP26, the attachments were stored in the attachments directory (the attach.path property in They were stored in this folder structure
  • AttachDirectory
    • tableId-recordId
      • Attachment.
But in few file systems like ext3 where there is a limit of 32k subfolders, this would exceed the maximum number of folders allowed.
To overcome this, the attachment model has been updated to save the attachment from 3.0MP26. For eg, for table Id “259”, recordId “0F3A10E019754BACA5844387FB37B0D5″, the file directory returned is “259/0F3/A10/E01/975/4BA/CA5/844/387/FB3/7B0/D5″. i.e,

–> AttachDirectory

—> 259
—-> 0F3
—–> A10
——> E01
——-> 975
——–> 4BA
———> CA5
———-> 844
———–> 387
————> FB3
————-> 7B0
————–> D5
—————> Attachment

Note that the attachments can be still be stored using the previous model by enabling the preference ‘SaveAttachmentsOldWay’ to ‘Y’. For more information on using preferences refer here.

API’s for Attachments Management:

Before these improvements, attachments were fetched using the standard folder name of tableId-recordId. Now API’s have been introduced to fetch the attachments and also to get the directory where attachment have to be stored in the improved model based on the preference ‘Save Attachments Old Way’.

API for fetching existing attachments:

The attachment can be fetched through an API method in TabAttachments. The method TabAttachments.getAttachmentDirectory can be used to fetch a particular attachment. The arguments to be passed are:
  • UUID of the ad_table
  • UUID of the record
  • fileName
It returns the path of the attachment relative to the attachment directory. The attachment directory can be fetched from Openbravo properties in java code using OBPropertiesProvider. Here is a blog on how it can be used. For eg., to fetch an attachment test.txt of recordId 0F3A10E019754BACA5844387FB37B0D5, tableId 259, the method can be used as follows:

String attachmentDirectory = TabAttachments.getAttachmentDirectory(“259″,”0F3A10E019754BACA5844387FB37B0D5″,”test.txt”);

API to fetch directory to save new attachments

When saving new attachments, the method TabAttachments.getAttachmentDirectoryForNewAttachments can be used to fetch the directory in which the attachment has to be stored. The arguments to be passed are, tableId and recordId . The value returned is the directory to save the record.Note that the directory returned is relative from the attachment directory of Openbravo.

TabAttachments.getAttachmentDirectoryForNewAttachments (“259″,”0F3A10E019754BACA5844387FB37B0D5″);

Migrating existing attachments to the improved model

Existing attachments can be migrated based on the latest model using an ant task. The task can be executed using the following command,

ant migrate.attachments 

the customer instance does not have any extension that is using API to retrieve attachments, no change for them is required, no need to migrate attachments. New attachments will be saved and retrieved using new approach, old – retrieved old approach.

If there is an extension that uses the old API then two options are possible
1. Switch on the mode to save attachments old way and that is it (short-term solution).

2. Change the extension to use new API and migrate attachments (recommended for the mid-term, long-term).  Contact us through our forum or through our social network channels  for any doubts. 

Previous post

Leveraging on Spreadsheet Familiarity to Increase Software Adoption

Next post

The Importance of Organizing Documentation Within a Company


  1. Velmurugan
    July 25, 2014 at 10:29 AM

    Hi Shankar,

    This model works great for us, however as we upload attachment’s to most of the documents(sales order, invoice etc.) searching the attached file becomes very difficult .. we need to remember the document no and then go to attachment section of the grid view , finally click download to see the file content .

    Is there a way to quickly find out the attached file in Openbravo?


    as soon as we type the “document no” in the quick launch, we should be able to see the attachments a in separate view/window , then click on download. In that way we do not need to go to a particular document to just download the attachments.

    Thanks ,

  2. Shankar Balachandran
    July 28, 2014 at 4:48 AM

    Hi Vel,
    Thanks for your comment. I think such a feature does not exist out of box. But you can add it to your custom module quite easily. There is a table c_file that manages all the document information, if you create a window for it then you can easily find the attachment record that you want by filtering through document number and by writing a simple process you can download the corresponding file.

    But I think what you are expecting is a document management module and you can check in the exchange, if there are any such modules.

  3. Wilfredo Moreno
    January 20, 2015 at 4:39 AM

    Buenas noches!

    Reciba un cordial saludo,

    Excelente post!

    ME surge una duda, como podría limitar al usuario para que no puedas eliminar o descargar el archivo adjunto a nivel de roles? o simplemente deshabilitar las opciones de eliminar archivo adjunto.

  4. Shankar Balachandran
    January 22, 2015 at 1:08 PM

    Hi Wilfredo,
    I think this can be done using preferences which is in this blog You can disable access to the attachments section for a particular role or user. Can you try to use these preferences?


Leave a reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>