attachment on catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 06:58 AM
I have created catalog item , have a requriment to validate attachment size on onsubmit catalog script.
above catalog item sys_id=1c006ba297c67110dc42b380f053af9a which is visible in url
In above attachment table attachment have different sys_id.
Please help me out how to validate attachment size on catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 07:32 AM - edited 10-26-2023 07:32 AM
Hi,
Check Hannah & Sachin's reply here
Require minimum attachment size in portal on catal... - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 11:51 AM
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);
}