- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 05:28 AM
Hi,
I have a requirement to make the attachment mandatory on the catalog item. User does not use service portal, so I cannot use "mandatory checkbox" in the catalog. My requirement is to check if the user has attached the file before submitting the catalog. If not, show them error message "Please attach a file".
How can I achieve that?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 03:10 AM
Hi Anurag,
I used below code in onSubmit catalog client script and it worked for me:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 05:35 AM
For Desktop:
function onSubmit() {
var cat_id = g_form.getParameter("sysparm_item_guid");//This will return the sc_cart_item sys_id that is reserved.
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item"); //unnecessary, but improves query efficiency
gr.addQuery("table_sys_id", cat_id);
gr.query(); //synchronous for non-service portal CMS.
if (!gr.hasNext()) {
g_form.addErrorMessage("Please Attach a File");
return false;
}
}
}
}
For Mobile/Service Portal:
function onSubmit() {
//Type appropriate comment here, and begin script below
var condition= g_form.getValue('condition');
if(condition=='upload_file')
{
if (this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage('Please Attach a file');return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 05:47 AM
You should not use glide record in a client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 05:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 05:46 AM - edited 01-09-2024 05:46 AM
Just tested this (onsubmit catalog client script) and it works
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('You must attach the completed form before submitting this request.');
return false;