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

Mahira
Tera Guru

Hi Abhijeet,



Yes you can write a business rule to check the name and type you have mentioned above. However I am not sure if you can check if the excel sheet is of 2007 format. All you can check is if it an excel.



See the screeshot of the attachment table



Capture.JPG


Hi Mahira,



I am not sure about the code that I need to write in Business rule. I cant figure out how to get the file name that is being attached to the record.


HI Abhijeet.,



Is the requirement to check if the user has attached an 2007 excel file?


If it is not a 2007 excel sheet what do you want to do?



Regards,


Mahira


Hi Mahira,



User should be allowed to attach excel 2007 file only. If user attaches any other file format ( To that table only ) then it should not submit the form. If the file format is different then it will throw alert to change file.