Script to Run on catalog item to Count and Limit Attachment Number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2021 04:58 AM
HI
I need to limit the number of attachments to 1 on the catalog item while ordering
i have checked yours previous answer available here Limit number of attachements on catalog Item - Developer Community - Question - ServiceNow Community but it not working.
i written some code to find attachment is attached or not, but how to add filter to count the number of attachments
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 12:36 AM
Hi
I have tried below code but it is not working ..
Function onSubmit() {
//Type appropriate comment here, and begin script below
var sys_id = g_form.getUniqueValue();
var gr = new GlideRecord('sys_attachment');
//gr.addQuery("table_sys_id", cat_id);
gr.addQuery('table_sys_id',sys_id );
gr.Query();
var totalSize=0;
while(gr.next()) {
totalSize = parseInt(gr.size_bytes);
totalSize=(totalSize / Math.pow(1024, 2)).toFixed(2) * 1;
if(totalSize > 5) {
alert("Attachment size exceeded");
return false;
}
}
}