- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2014 02:39 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2014 09:27 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2014 09:27 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2014 10:34 PM
Hi Abhiram,
Its working as expected. Thanks a lot !
regards,
Abhijeet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2017 08:44 AM
Thank you Abhiram it was very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2014 09:52 PM
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;