Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 01:22 AM
Hi Team,
I have a check box in my catalog item
- If the user checks that check box then he must attach an attachment
- If the user not checking that check box in this case he can submit the catalog item without attaching.
Please let me know how to get this done?
Thanks in Advance.,
Balaraju K B
Solved! Go to Solution.
Labels:
- Labels:
-
Team Development
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 02:46 AM
this onSubmit client script should help
1) Ensure the Isolate Script field is set to false for this client script
2) By default when you create new client script it is true
Note:
Ensure you give valid checkbox variable name and your message for alert/form message
function onSubmit() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('checkbox_variable').toString() == 'true'){
if(window == null){
// portal
if(this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage('You must add attachment before submitting this request.');
return false;
}
}
else{
// native view
var length = $j("li.attachment_list_items").find("span").length;
if(length == 0){
g_form.addErrorMessage('You must add attachment before submitting this request.');
return false;
}
}
}
}
Regards
Ankur
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
15 REPLIES 15

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 02:03 AM
function onSubmit() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('your_variable_name_here') == "No")
{
try {
var msg = 'This request requires an attachment. Please review the form and try again.';
var attachments = document.getElementById('header_attachment_list_label');
//g_form.addInfoMessage("Attachment visibility: " + attachments.style.visibility + " attachment display: " + attachments.style.display);
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert(msg);
return false;
}
}
//For Service Portal
catch(e) {
var count = getSCAttachmentCount();
if(count <= 0) {
alert(msg);
return false;
}
}
}
}