Download Attachment

sachin312
Giga Expert

Hi,

I am trying to download a attachment from business rule. Because, I want to download attachment when it is created on "sys_attachment" table. Is it possible?

The only way I found to download attachment is by using action.setRedirectURL('sys_attachment.do?sys_id=' +SOME SYSID) in UI Action. Is there any other way to do this?

Note: I tried gs.setRedirect() in business rule. But no use.

6 REPLIES 6

adiddigi
Tera Guru

You cannot download an Attachment from a Business Rule.



Can you explain the business problem you are trying to solve?


sachin312
Giga Expert

We have a UI Action which creates a PDF and attached to the table as attachment. The users also want the attachment to be download at the same time. Is there any way to call UI Action from any script?


adiddigi
Tera Guru

After the UI Action attaches the attachment to the record, use gs.setRedirect() with the URL to the attachment that was attached before. If it is still unclear, please post the UI Action.


var attach = new GlideRecord('sys_attachment');


        attach.addQuery('table_sys_id', current.sys_id);


        attach.addQuery('table_name', 'u_req');


        attach.orderByDesc('sys_created_on');


        attach.query();


  if(attach.next()){


  gs.setRedirect('sys_attachment.do?sys_id='+attach.sys_id);


  gs.log('Attach: '+attach.file_name);


  }



This will download the attachment which is created early but not the latest one. As latest one is created after running the UI Action.