- 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:
-
Team Development
- 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
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-16-2020 02:25 AM
Can you check if it is working on portal or not?
can you update as below and check for the else part
else{
// native view
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none'){
g_form.addErrorMessage('You must add attachment before submitting this request.');
return 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-20-2020 08:49 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate answer as correct & helpful to close the thread.
If not, please let us know if you need some more assistance.
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-21-2020 11:26 PM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark my response as correct & helpful so that this thread can be closed and others can be benefited by this.
If not, please let us know if you need some more assistance.
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
10-01-2020 07:48 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark my response as correct & helpful so that this thread can be closed and others can be benefited by this.
If not, please let us know if you need some more assistance.
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
02-16-2022 01:08 AM
I used this in a condition when I enter a domain that ends with the word 'com' in a single text input field, then the checkbox should be visible (implemented this using UI policy) and when the checkbox is true then the attachment is mandatory (implemented using the code you gave).
Say for instance if I enter the domain 'example.com' and then the checkbox is visible. If I don't attach something, I get the error as per the code and then I change the domain as 'example.co.uk'. If I submit now, I still get the error.
Please help on how to solve this.