Attachment Variable max_file_size for less than 1mb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 10:44 AM
Hello,
Knowing that we can set attachment variables of a catalog item such as max_file_size and allowed_extensions. Does anyone know a way to limit the max file size to a value of less than 100kb? (Less than 1mb)?
It would seem the max_file_size is in mb's and I've tried values like max_file_size=0.1 but it does not work.
This would be easier than writing a business rule....
If this is not possible, does anyone have an example to limit a portal catalog attachment size to less than 100kb before a user clicks "submit"?
Cheers,
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 12:26 PM
Hello Gerrity,
System property is present OOB. You have to restrict attachment size for all attachments? if yes then you can update the same in the mentioned property.
Regards,
Palak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 12:33 PM
Hello All,
Let me try to clarify.
I do not want to set the global system setting for attachment size. I'm looking to set the maximum attachment size for a catalog item I'm creating to be less than 100kb.
The problem is that the attachment variable (catalog item variable) can use the max_file_size attribute but this has to be an integer and that is in MegaBytes. Thus you can't set max_file_size=0.1 (not an integer).
So, I'm looking for a way to build a catalog item attachment that will limit the file size to less than 100kb.
I was hoping it could be done with a catalog client script with an onSubmit function but I'm not too familiar with jquery to code it.
Does anyone have a sample bit of code I could work with?
Was hoping something like this: (Catalog Client Script)
function onSubmit() {
if(this.document.getElementsByClassName('get-attachment').size_bytes > 999) {
g_form.addErrorMessage(getMessage('attachment has to be less than 100kb'));
return false;
}
}
Cheers all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2022 08:17 AM
Hello All,
I've been doing some digging and testing. There is a field called "size_bytes" but I can't seem to get this client script to work properly. The If (att.size_bytes > 1000) just ignored and the else statement always executes.
Any ideas on how I can check the size of an attachment and force it to be less than 10kb?
function onSubmit() {
var sys_id = g_form.getUniqueValue();
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id',sys_id);
att.query();
if (att.size_bytes > 1000) {
var confirm_box = confirm('Too Big!');
return false;
}
else{
var confirm_box2 = confirm('Size ok');
return true;
}
}
Thanks All!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2022 10:30 AM
Hi
Please follow the steps below to achieve your requirement:
1) Create a Before Insert Business Rule on Attachment Table and use the details below:
BR Details:
Table Name: Attachment(sys_attachment)
When: Before Insert
Condition: Table is sc_cart_item
Script:
Just make sure by uploading a attachment to your catalog item form and check what is the table name which gets updated in Attachment table. It should be sc_cart_item, but just be double sure and change it if it is something different and rest all script remains same.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(parseInt(current.size_bytes) > parseInt(1000000)){
current.setAbortAction(true);
}
})(current, previous);
This script will not allow users to upload the Attachment which are greater than 1 MB. Now write a Catalog client script and validate once user click on Submit button that they have uploaded the attachment or not.
If the size will be greater than 1 MB which they have uploaded the Business Rule will not upload the document and now your client script which checks for attachment present against that item will not allow it and user will have to upload it again.
You can also display a info message in your client script itself to upload the attachment of smaller size:
For attachment mandate, just refer to below blog which list multiple method to do this:
https://community.servicenow.com/community?id=community_article&sys_id=0f0c5290dbe7f380d82ffb24399619f5
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 07:19 AM
Hello All,
With the help of
Script to Run on catalog item to Count and Limit Attachment Number - IT Service Management - Questio... (scroll to the bottom)
Thanks everyone for your help!