Help Needed: Preventing Attachment of .zip Files in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 12:12 AM
Hello ServiceNow Community,
I hope this message finds you well. I'm currently facing an issue with preventing the attachment of .zip files in my ServiceNow instance. Despite implementing a script to restrict the attachment of .zip files, null entries still appear in the Manage Attachments section after an attempt to attach a .zip file.
Here's a summary of the problem and what I've done so far:
When attempting to attach a .zip file, although I receive the expected error message indicating that .zip files are not allowed, null entries still appear in the Manage Attachments section.
What I've Tried: I've implemented a business rule script which runs on the sys_attachment table and specifically targets the before insert event. In the advanced condition section of the business rule, I've specified the condition current.table_name == 'u_random_table' to ensure that the script only executes when attachments are being added to records in the u_random_table. Despite these efforts, it seems that the script is not entirely successful in preventing the creation of attachment records for .zip files, leading to the appearance of null entries in the Manage Attachments section.
Script Details:
(function executeRule(current, previous /*null when async*/) {
if (current.getValue('random_table_name') == 'u_random_table') {
var fileName = current.getValue('file_name');
// Check if the file name contains ".zip"
var zipIndex = fileName.indexOf('.zip');
// If ".zip" is found in the file name, display error message and abort
if (zipIndex != -1) {
gs.addErrorMessage('Attachment of .zip files is not allowed.');
current.setAbortAction(true);
}
}
})(current, previous);
```
Request for Assistance:
I'm seeking guidance and insights from the community on how to properly prevent the attachment of .zip files without resulting in null entries in the Manage Attachments section. Any suggestions, alternative approaches, or insights into what might be causing this issue would be greatly appreciated. Please go through pic attached for your reference.
Thank you in advance for your help and support!
Thanks & regards,
Sunayana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 12:19 AM
Why not just add them to the property 'glide.attachment.extensions'. This will prevent them from being attached and a quick test showed no 'null' entries.
https://[your_instance ].service-now.com/sys_properties_list.do?sysparm_query=name%3Dglide.attachment.extensions&sysparm_view=
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 12:55 AM
Hi @Mark Manders ,
Thank you for your suggestion!
Just to clarify, I noticed that 'zip' is already included in the 'glide.attachment.extensions' property. However, my concern is whether removing 'zip' from this particular list will affect all other tables and their attachment functionalities.
Additionally, I want to emphasize that the current requirement is to prevent users from attaching .zip files to a specific table without affecting other tables' attachment functionalities. The specific requirement is:
"When I try to upload a zip file as an attachment in the random record, I should not be able to complete the action and receive an error prompt.
Validation to be placed on upload of the attachment.
Error message -
'Zip File is not allowed as an attachment.'"
Do you have any insights on how we can achieve this?
Once again, thank you for your assistance!
Thanks & regards,
Sunayana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 01:21 AM
I read your 'preventing the attachment of .zip files in my ServiceNow instance' and missed the specific table part.
What you are doing, is aborting the attachment 'attaching' to the record. The attachment is being created as a separate record and related to the record you are attaching it to. You will need to perform a delete on the attachment record and not a simple 'abort action'.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 04:55 AM
Hi Mark,
Thank you for your response and for pointing out the issue. I understand that I need to delete the attachment record instead of simply aborting the action.
Could you please provide further guidance or an example on how to correctly incorporate the deletion of the attachment record into my script? I'm finding it a bit challenging to get it right and would greatly appreciate your help.
Thank you in advance for your assistance!
Thank you,
Sunayana.