Require minimum attachment size in portal on catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 01:58 PM
Hello!
I have an onSubmit client script that prevents a user from submitting the catalog item without an attachment, but is there a way to require a minimum file size? Before they can submit this catalog item in the portal I want it to make sure they have a minimum file size of 65 KB.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 02:05 PM
You will have to use GlideAjax to query sya_attachment to determine size of file and provide validation message to user.
Your script include will return flag value based on attachment size.You can use below sample code in your script include
var grInc = new GlideRecord('sys_attachment);
grInc.addQuery('table_name',"incident");
grInc.addQuery('table_sys_id',current.sys_id);
grInc.Query();
var totalSize=0;
while(grInc.next()) {
totalSize+= parseInt(grInc.size_bytes);
}
if(totalSize+parseInt(current.size_bytes) > <your Size Limit>) {
gs.addInfoMessage("Attachment size exceeded");
current.setAbortAction(true);
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 02:18 PM
Hi thank you for the response! I'm a little confused...won't the attachment not be on the sys_attachment table yet though because they haven't submitted it yet?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 02:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2019 01:24 PM
Ok I started building the scripts based on your suggestions but need some help as it is not working. Please let me know if you have any suggestions!!
Script Include:
var AttachmentSize = Class.create();
AttachmentSize.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkAttachment : function() {
var gr = new GlideRecord('sys_attachment');
gr.addQuery ('table_name', 'sc_cart_item');
gr.addQuery ('table_sys_id', current.sys_id);
gr.query();
var totalSize = 0;
while (gr.next()){
totalSize += parseInt (gr.size_bytes);
}
if (totalSize+parseInt(current.size_bytes < 65)){
return false;
}
else
{
return true;
}
}
});
Client Script (onSubmit on the catalog item):
function onSubmit() {
function ValidateAttachment(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true'){
return;
}
if(g_form.getValue('sbg') == 'aero' && answer == 'false'){
alert('You must download, complete, and attach the User Security Request form before submitting this request. Please make sure all of the required fields are populated.');
return false;
}
}
var ga = new GlideAjax('AttachmentSize'); //Name of Script Include
ga.addParam('sysparm_name', 'checkAttachment'); //Name of the function in the script include
ga.getXML(ValidateAttachment);
}