Need to add the attachment validation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 07:53 AM
Hi All,
I am working on the one of the form, in this form I need to restrict the form submission when "Are you able to browse wireless network. If Yes attach screenshot." and " Do you get any error message? If Yes attach screenshot." both the variables is Yes, if the use is not attached the screen shot I need to populate the alert message and need to restrict the form submission.
I wrote the onSubmit client script but it is not working as expected.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 08:29 AM
@vinuth v Please refer to this tutorial to make attachment mandatory on the catalog item form https://www.basicoservicenowlearning.in/2020/10/attachment-mandatory.html
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 10:36 AM
Hello @vinuth v ,
The following Client Script would work for a catalog item on Native UI & Service Portal:
TYPE: onSubmit
UI Type: All
Isolate Script: False
Script:
function onSubmit() {
var cat_id = g_form.getValue('sysparm_item_guid');
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must add an attachment before submitting this request.");
return false;
}
}
The above code restricts the form submission if there's no attached attachment.
Please add conditions as needed.
Thanks,
A. A. B