Clarity

Expand all | Collapse all

Send Attachment File via

  • 1.  Send Attachment File via

    Posted Jul 04, 2018 03:05 PM

    I have an attachment field on the issues object.

     

    I need to send this attachment via an email notification. How can I get the file location so I can passed it to the< email:email> Gel routine. I am using MS SQL.

     

    Regards,

     

    Joni



  • 2.  Re: Send Attachment File via

    Posted Jul 05, 2018 04:08 AM

    One way could be , you XOG out the issue instance. Make sure you specify the argument documentLocation in the XOG read file. Once that is done, the document will be exported to that location and can be referred in jelly:email.



  • 3.  Re: Send Attachment File via

    Posted Jul 05, 2018 04:25 AM

    Hi joni.campos

     

    You can use the below query to get the folder structure of a file store in attachment attribute. And then we can create the full path where it is stored.

     

    select
    cdfd.PATH_NAME,
    mig.data_to_b_imp folder_id
    ,mig.code folder_code
    ,mig.name folder_name
    ,cast(flv.id as VARCHAR(30)) file_version_id
    ,substring(cast(flv.id as VARCHAR(30)),2,3) path_one
    ,'00'+ substring(cast(flv.id as VARCHAR(30)),1,1) path_two
    ,fl.name file_name
    ,fl.mime_type
    from
    <table_name> mig --table where attachment attribute is created
    left outer join CLB_DMS_FILES FL on FL.PARENT_FOLDER_ID = mig.data_to_b_imp
    left outer join CLB_DMS_VERSIONS FLV on FLV.FILE_ID = FL.ID
    left outer join CLB_DMS_FOLDERS CDFD on (FL.PARENT_FOLDER_ID = CDFD.id)
    where
    mig.code = 'riskmigration' --code

     

    <!-- Set the Folder Path for File -->

     <core:set value="\" var="FS"/>

     

    --Create path where file is stored.


    <core:set value="${FinLoadDtlRow.path_one}" var="path1"/>
    <core:set value="${FinLoadDtlRow.path_two}" var="path2"/>
    <core:set value="${FinLoadDtlRow.file_name}" var="thisDocumentName"/>
    <core:set value="${FinLoadDtlRow.file_version_id}" var="thisDocumentId"/>
    <core:set value="${thisClarityConfig.getProperties().getSearchServer().getFilestoreDir()}" var="Filese"/>
    <core:set var="thisDocumentRoot">${Filese}${FS}clarity${FS}Files${FS}${path1}${FS}${path2}</core:set>
    <core:set var="FullFilePath">${thisDocumentRoot}${FS}${thisDocumentId}</core:set>

     

    From the above we can use the ${FullFilePath} variable to pass in the <email:email> tag.

     

    <email:email to="user@example.com"
    from="username@mailserver.com"
    subject="File Attached."
    server="${mailServer}"
    attach="">
    File Attached.
    </email:email>

     

    Hopefully this can help you to achieve your requirement.



  • 4.  Re: Send Attachment File via

    Posted Jul 05, 2018 02:45 PM

    You most likely will need to load the ${FullFilePath} into a java.io.File object as org.apache.commons.jelly.tags.email tag is looking for that type of object for the Attach attribute.

     

    One thing that was always bother me was dealing with documents store in the database vs file system.  In poking around I have found a class that figures this out.

     

    The com.niku.dms.util.FileUtil class has a static method retrieveFileData which takes a stored file’s versionId and returns a byte array of the file no matter where it is stored.

     

    To attach it, just create a temporary file:

     

    File tempFile = File.createTempFile(prefix, suffix, null);
    FileOutputStream fos = new FileOutputStream(tempFile);
    fos.write(byteArray);

     

    I would recommend deleting the temp file after the sending of the email.

     

    V/r,

    Gene



  • 5.  Re: Send Attachment File via

    Posted Jul 09, 2018 09:07 PM

    Hi Sridhar,

     

    Thanks for your fast reply.   I tried your solution and although I can export the file. The exported file from the XML does not contain the correct file name with extension.



  • 6.  Re: Send Attachment File via

    Posted Jul 09, 2018 09:12 PM

    Hi Smiriti,

     

    Thanks for your fast reply.

     

     

     

    I am converting your solution to MS SQL code and give it I try, although I could not understand the column names bello ( they are not part of my issue object).

     

    mig.data_to_b_imp folder_id
    ,mig.code folder_code
    ,mig.name folder_name

     



  • 7.  Re: Send Attachment File via

    Posted Jul 10, 2018 01:40 AM

    Hi Joni

     

    The above query that i have shared is based on a custom object. So in your case we need to do some modification on that particular columns.

     

    Here mig.data_to_b_imp refers the attachment attribute name. Like if in your case the name of attribute is idea_attachment then here you need to pass mig.idea_attachment. And if you want to have the id of that particular idea where the attachment is store then in place of mig.code you can use mig.id as in odf_ca_idea we have column with id.Similarly in place of mig.name we can modify the query to get idea name.



  • 8.  Re: Send Attachment File via

    Posted Jul 12, 2018 10:43 AM

    Hi Smiriti,

     

    I managed to send an email with an attached file. The problem now is the the attached file does not have the correct name or extension. Any ideia how to solve this ?



  • 9.  Re: Send Attachment File via

    Posted Jul 16, 2018 05:28 AM

    Hi joni.campos

     

    You are not getting the file name in email because the files is being stored in the server with an id.

    For example a file with name 'ABC' will be stored as 5150503 in the server. If you want to change the name of file.Then you have to rename it.



  • 10.  Re: Send Attachment File via

    Posted Jul 16, 2018 02:20 PM

    Hi Smiriti,

     

    The problem here is that we can not rename the file that is in the path we found (ca ppm will loose its reference to the file).

     

    I am assuming that we have to make a copy to a temporary folder and then rename the file to the correct name and extension ( I found a Gel Script that does that ...). 

     

    Unless we can rename the file name in the <email><email> attach tag...



  • 11.  Re: Send Attachment File via

    Posted Jul 17, 2018 01:47 AM

    Hi Joni,

     

    Yes correct that is what I was trying to tell you.

    First we need to read the file from server then save it in temp folder after that rename the file all using gel script.