onsubmit catalog client scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 09:14 PM
I have onsubmit catalog script and i want to set a mandatory field for attachment when user select both options as per below.
When I select Request Type (variable A) is New Cert (variable B) and Use Case Type (variable C) is Public (variable D) the attachment is mandatory field.
this is the onsubmit script currently i have.
"function onSubmit() {
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 09:30 PM
Please see the screenshot below for the code required to make attachments mandatory.
Cline script
Script include
Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution
Thanks
Eshwar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 09:44 PM
Hi Eshwar,
the screenshot you have attach is too small and blurry... can you copy the scripts in here.
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 10:43 PM
Hi @TMKAM
Update script :-
function onSubmit() {
// Get values of both variables
var requestType = g_form.getValue('variable_A'); // Replace with the actual variable name for Request Type
var useCaseType = g_form.getValue('variable_C'); // Replace with the actual variable name for Use Case Type
// Check if Request Type is "New Cert" and Use Case Type is "Public"
if (requestType == 'variable_B' && useCaseType == 'variable_D') {
// Check if any attachments exist
if (this.document.getElementsByClassName('attachment_list_rows').length == 0) {
alert("You must add attachments before submitting this request.");
return false; // Prevent form submission
}
}
// Allow form submission if conditions are not met
return true;
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 11:14 PM
Hi ravi gaurav,
i have change a bit the catalog client scripts because the scripts still prompt the alert even after i have attach the file.
thank you
Update script :-