To get Attachment file name and file format

abhiyadav2001
Giga Expert

Hi,

 

I would like to see of the attachment name is 'myfile.xls'. Here I have to check two things

1. File should be in excel 2007 format

2. file name should be 'myfile'

 

I can not edit 'attachment' form as it applies to every module. I am thinking to write a business rule. How can I achieve above objectives ?

Any one worked on the same stuff before?

 

Thanks,

Abhijeet

1 ACCEPTED SOLUTION

adiddigi
Tera Guru

var gr = new GlideRecord('sys_attachment');


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


gr.query();


if(gr.next()){//use `while` if dealing with multiple attachments


  if(gr.getValue('file_name').indexOf('xlsx') != -1 && gr.getValue('file_name').indexOf('myfile') != -1){//meaning if you find a file with xls extension


  //do something


  }


}







You could even check for content type, but until and unless you are doing this check for an integration you should be fine in majority of cases.



Or, even better if you know the name and extension of the file is same meaning the name of the file and the extension is myfile.xlsx then you could just do that check in the `if` using the |indexOf| method.


View solution in original post

8 REPLIES 8

adiddigi
Tera Guru

var gr = new GlideRecord('sys_attachment');


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


gr.query();


if(gr.next()){//use `while` if dealing with multiple attachments


  if(gr.getValue('file_name').indexOf('xlsx') != -1 && gr.getValue('file_name').indexOf('myfile') != -1){//meaning if you find a file with xls extension


  //do something


  }


}







You could even check for content type, but until and unless you are doing this check for an integration you should be fine in majority of cases.



Or, even better if you know the name and extension of the file is same meaning the name of the file and the extension is myfile.xlsx then you could just do that check in the `if` using the |indexOf| method.


Hi Abhiram,



Its working as expected.   Thanks a lot !



regards,


Abhijeet


S M
Tera Contributor

Thank you Abhiram it was very helpful.



adiddigi
Tera Guru

If it's client side, the code is slightly different as `current` isn't available on client side.



you should be using   g_form.getUniqueValue() ; in the place of current.sys_id;