Conditional Mandatory Attachment for Catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Hi Team,
I have a requirement on a Service Catalog Item where an attachment should be mandatory based on a
variable selection.
Requirement
Catalog Item has a Select Box variable: request_type
Values:
Bank Account Maintenance
Scheduler Maintenance
Other
When request_type = Bank Account Maintenance OR Scheduler Maintenance, an attachment must be mandatory
For Other, attachment is not required
What I Tried
I implemented a Catalog Client Script (onSubmit) to validate attachments using g_form.getAttachments().
function onSubmit() {
var requestType = g_form.getValue('request_type');
// Check only for required options
if (requestType == 'Bank Account Maintenance' || requestType == 'Scheduler Maintenance') {
var attachments = g_form.getAttachments();
if (!attachments || attachments.length === 0) {
alert('Attachment is mandatory for Bank Account Maintenance or Scheduler Maintenance requests.');
return false; // Stop submission
}
}
return true;
}
Not working - any one please help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
45m ago
Hello @nameisnani
function onSubmit() {
var requestType = g_form.getValue('request_type');
// Check only for required options
if (requestType == 'Bank Account Maintenance' || requestType == 'Scheduler Maintenance') {
if (this.document.getElementsByClassName('get-attachment').length == 0) {
alert('Attachment is mandatory for Bank Account Maintenance or Scheduler Maintenance requests.');
return false; // Stop submission
}
}
return true;
}
If my response has helped you, hit the helpful button, and if your concern is solved, do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
32m ago
you want this validation in native or portal OR Both?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
