How to calculate Image width and height?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 02:31 AM
Hello,
I have a requirement in which we have to validate image width and height of the image file attached to the catalog request.
There is similar functionality in Images(db_image) table OOB. if we upload any image it directly calculates image width and height but I am unable to trace the code which is performing this functionality.
Please suggest an approach or possible solution to perform this activity.
Note: Our instance is in Fuji
Best Regards,
Rajesh M.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 01:20 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 03:12 AM
Hello Raj,
Use the script:
var result = {
height: 0,
width: 0,
size: 0,
file_name: ''
};
function getProperties(sys_id){
var ga_att = new GlideRecord ("sys_attachment");
ga_att.addQuery('table_sys_id', sys_id);
ga_att.query();
while (ga_att.next()){
result.height = ga_att.image_height;
result.width = ga_att.image_width;
result.size = ga_att.size_bytes;
result.file_name = ga_att.file_name;
}
}
getProperties('<sys_id_of_catalog_item>')
// like that: getProperties('6924a5e20409a9881bad70394a55cb63')
Then result object holds all the properties.
Note: the result of this query is not visible in the Table, without the roles sys_attachment
EDIT:
if you have more than one attachment, try this one:
var attachments = [];
function getProperties(sys_id){
var ga_att = new GlideRecord ("sys_attachment");
ga_att.addQuery('table_sys_id', sys_id);
ga_att.query();
while (ga_att.next()){
var result = {
height: 0,
width: 0,
size: 0,
file_name: ''
};
result.height = ga_att.image_height;
result.width = ga_att.image_width;
result.size = ga_att.size_bytes;
result.file_name = ga_att.file_name;
attachments.push(result)
}
}
getProperties('<sys_id_of_catalog_item>')
attachements
// This will return an array of object that are attachment properties
Regards,
Michal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2016 11:17 AM
Do you have to enable some feature on ServiceNow to populate the "image_height" and "image_width" values? When I try to execute this script on the server for a GlideRecord object, it simply returns and empty string. I also tried those properties on a GlideSysAttachment object, but they just came back as 0.
Thanks,
Dan Morella

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 10:06 PM
Hi Michal,
Thanks for the script, but how we're going to use it? in client script? can guide us more. thanks a lot