Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This ServiceNow client script is designed to validate file attachments on a form before submission. It's most likely used as a "Client Script" or "Client Script in a Catalog Item" that runs in the browser when a user tries to submit a form.

This client script runs when a form is submitted in ServiceNow. It checks if the user has:

Attached at least one file (shows an error if none).
Attached no more than three files (shows an error if more).
Only uploaded files of type PDF or PNG (shows an error for other types).
If any of these checks fail, the form submission is blocked and an appropriate error message is displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(function executeRule(gForm, gUser, gSNC) {
var attachments = gForm.getAttachments();
if (!attachments || attachments.length === 0) {
gForm.addErrorMessage("You must attach at least one file.");
return false;
}

if (attachments.length > 3) {
gForm.addErrorMessage("You can only upload up to 3 files.");
return false;
}

var allowedTypes = ['pdf', 'png'];
for (var i = 0; i < attachments.length; i++) {
var fileName = attachments[i].file_name.toLowerCase();
var ext = fileName.split('.').pop();
if (!allowedTypes.includes(ext)) {
gForm.addErrorMessage("Only PDF and PNG files are allowed.");
return false;
}
}

return true;
})(gForm, gUser, gSNC);
Loading