- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2020 09:05 AM
Hi All,
I want to make attachment mandatory based on a specific field values selected for a catalog item when the user will submit the form.
When the User will select the check box above and try to submit the form then attachment made will be mandatory.
if not checked there will be no message appear and the form will be submitted without any issue.
Thanks,
Sambit
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 06:53 AM
Hi,
Please refer below links, it might help you.
OnChange variable to make Attachment Mandatory Client Script
Mandatory Attachment on Submit based on Catalog Item Variable
Mark it correct and helpful.
Thanks
Bhagyashri Sorte.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 06:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 07:19 AM
please ensure Isolate Script is set to false for this onSubmit client script
please share your script
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
‎08-24-2020 10:14 PM
Hi Ankur,
I truly appreciate your continuous support regarding my queries.
Please find the script below which helped me to resolve my issue.
------------------------
function onSubmit() {
var condition= g_form.getValue('u_for_client_own_use');
try{
if(condition=='true')
{
//Condition to make attachement mandatory is true
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 the License request File");
return false;
}
}
}catch(e){
g_form.addErrorMessage(e);
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 10:22 PM
Hi sam,
I have provided the same script in the above and below comments also.
If you think it is helpful, please mark my response as correct and helpful.
Thanks,
Sriram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 10:39 PM
Just to information it is not good practice to use GlideRecord in client script.
This won't work in portal as Portal doesn't allow GlideRecord.
Please check the approach mentioned in my previous comment and try that once and let me know if any issues.
Mentioning again here
Note: ensure isolate script field is set to false
function onSubmit() {
//Type appropriate comment here, and begin script below
var condition = g_form.getValue('u_for_client_own_use');
if(condition == 'true'){
if(window == null){
// portal
if(this.document.getElementsByClassName('get-attachment').length == 0) {
alert('Please Attach the License request File');
return false;
}
}
else{
// native view
var length = $j("li.attachment_list_items").find("span").length;
if(length == 0){
alert('Please Attach the License request File');
return false;
}
}
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader