Attachment name Validation on Service portal Before Catalog Item Submission
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 02:32 AM
Hello All,
We have a requirement where we have to validate the attachment name in service portal before catalog item name submission.
Example:
The attachment name should be "variance access form.xlsx", if user is trying to attach some other attachment we have to restrict the catalog item submission.
Thanks in Advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 04:00 AM
@Natraj S To validate the attachment name before submitting a catalog item in the ServiceNow Service Portal, you can use a client script to check the attachment name and prevent submission if it doesn't match the expected format. Here’s a solution using a onSubmit catalog client script, something like this and remove loop if there are not multiple attachments to verify,
function onSubmit() {
var expectedFileName = "variance access form.xlsx";
var isValid = false;
// Get all attachments associated with the catalog item
var ga = new GlideAjax('AttachmentAjax');
ga.addParam('sys_id', g_form.getUniqueValue());
ga.addParam('sysparm_name', 'getAttachments');
ga.getXMLAnswer(function(response) {
var attachments = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
// Check if any attachment matches the expected file name
for (var i = 0; i < attachments.length; i++) {
if (attachments[i].file_name === expectedFileName) {
isValid = true;
break;
}
}
// If not valid, show error and prevent submission
if (!isValid) {
g_form.addErrorMessage("Please attach the correct file: " + expectedFileName);
return false;
}
});
}
Hope this will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 05:48 AM