attachment on catalog item

auskamalla
Tera Contributor

I have created catalog item , have a requriment to validate attachment size on  onsubmit catalog script.

 

sp.PNG

above catalog item sys_id=1c006ba297c67110dc42b380f053af9a  which is visible in url

 

sp1.PNG

In above attachment table attachment have different sys_id.

 

Please help me out how to validate attachment size on catalog item. 

 

2 REPLIES 2

Anurag Tripathi
Mega Patron
Mega Patron

hi Anurag below code written by Hannah C by referring your link.

Please suggest your response.

 

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);


}