- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 12:58 PM
On our Service Portal, we have a Record Producer that creates a SAFE Epic (sn_safe_epic) record. Through integration, these records are being transferred over to Azure DevOps upon submission into ServiceNow.
The issue is that under certain scenarios, the users are required to attach a file to the Record Producer record on the Service Portal before submitting. We want to not allow them to submit the request if they have not attached any required files.
Unfortunately, it does not appear that we can use the "Attachment" field type on the Record Producer, as for some reason, ServiceNow will not send these attachments over to Azure Dev Ops. However, if we use the out-of-the-box "Add Attachments" link at the bottom of all forms on the Service Portal, ServiceNow will send over those attachments to Azure Dev Ops.
We are fine with doing that, but how can we create a Catalog Client Script to verify that they have actually attached a file before allowing them to submit?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 05:34 AM
you can use this onSubmit catalog client script and it will work in both native + portal
Example: if variable ABC has value as XYZ then make the attachment mandatory
Please enhance it as per your requirement
function onSubmit() {
//Type appropriate comment here, and begin script below
var variableValue = g_form.getValue('ABC');
try {
if (window == null) {
// portal
if (this.document.getElementsByClassName('get-attachment').length == 0 && variableValue == 'XYZ') {
alert('You must add attachment before submitting this request.');
return false;
}
}
} catch (ex) {
// native view
var length = getSCAttachmentCount();
if (length == 0 && variableValue == 'XYZ') {
alert('You must add attachment before submitting this request.');
return false;
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 06:40 AM
Yes, that code looks to be right out of the KB article link that Chris Burks provided, that we already verified does not work for us, presumably because of one of the three conditions I listed in my previous posts.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 06:47 AM
Sorry it didn't work for you, but mine worked on a Record Producer on the sn_safe_story table. It wasn't a part of an Order Guide, but other than that, the scenario seemed to match yours.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 06:50 AM
Thanks for trying and letting me know that. That helps us identify what may be causing the issue. I am not surprised, there are a few other things that do not work in Order Guides either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 06:35 AM
Maybe you can try with script include and on submit client script
Script include:
var CheckAttachments = Class.create();
CheckAttachments.prototype = {
initialize: function() {},
hasAttachments: function(requestSysId) {
var ga = new GlideAggregate("sys_attachment");
ga.addQuery("table_sys_id", requestSysId);
ga.addQuery("table_name", "sc_req_item"); // Or use 'sn_safe_epic' if attachments go there directly
ga.addAggregate("COUNT");
ga.query();
if (ga.next()) {
return ga.getAggregate("COUNT") > 0 ? "true" : "false";
}
return "false";
},
type: "CheckAttachments"
};
client script:
function onSubmit() {
var sysId = g_form.getUniqueValue(); // Get current record's Sys ID
var ga = new GlideAjax("CheckAttachments");
ga.addParam("sysparm_name", "hasAttachments");
ga.addParam("sysparm_sysId", sysId);
ga.getXMLAnswer(function(response) {
if (response === "false") {
alert("You must attach at least one file before submitting.");
g_form.clearMessages();
g_form.addErrorMessage("Attachments are required before submitting.");
return false;
}
});
return true; // Allow submission if attachments exist
}
Please mark correct/helpful if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 06:38 AM
Are you sure this script will work?
Did you test it?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader