Make attachment mandatory on both native UI and Service portal for a catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2021 11:43 PM
Hi all,
We created a new catalog item " Application Access", which contains Request type as a variable(Select box) with three choices.
Request type
-> -none-
-> Add
-> Modify
-> Remove
If Request type is Add or Modify, then need to make Attachment mandatory & if Request type is Remove then Attachment is not required.
Please help me with the best approach to achieve this.
Thank you,
Balaram.
- Labels:
-
Incident Management
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2021 01:46 AM
Hi Balaram,
You can have onsubmit client script to achieve this.
Please refer below code for you reference.
You catalog client script can be :
Type : onSubmit
Name : your choice
UI type : ALL
Isolate Script : false
script :
function onSubmit() {
//Checking Attachment
try { //Works in non-portal ui
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
if (g_form.getValue('<request type backend value') == 'add' || g_form.getValue('<request type backend value') == 'modify') {
alert('Please attach document.');
return false;
}
}
}
catch (e) {
if ((this.document.getElementsByClassName('get-attachment').length == 0)) {
if (g_form.getValue('<request type backend value') == 'add' || g_form.getValue('<request type backend value') == 'modify') {
{
alert('Please attach document');
return false;
}
}
}
}
Please check and confirm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2021 02:05 AM
refer my blog for achieving this requirement for native + portal
Verify Mandatory Attachments Count on Catalog Item
If it helps please mark blog as helpful and also bookmark it
Adding script for help from same blog of mine
Script: onSubmit
Note: Ensure Isolate Script field is set to False for this Catalog Client Script to ensure DOM manipulation works
function onSubmit() {
//Type appropriate comment here, and begin script below
var countRequired = 1;
if(g_form.getValue('request_type') == 'Add' || g_form.getValue('request_type') == 'Modiy'){
if(window == null){
// portal
if(this.document.getElementsByClassName('get-attachment').length != countRequired) {
alert('You must add attachments before submitting this request.');
return false;
}
}
else{
// native view
var length = $j("li.attachment_list_items").find("span").length;
if(length != countRequired){
alert('You must add attachments before submitting this request.');
return false;
}
}
}
}
Isolate Script: Set to False
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2021 12:23 PM
Thank you for sharing. it work for me.