- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 02:28 AM
Hi All,
I have a requirement to prevent form submission in service portal if the catalog item has no attachment when one of the fields has a certain value. I have tried onSubmit catalog client script with the following code, but it returns false even if the form has attachment. Please help me with this
function onSubmit() {
var request_type = g_form.getValue('u_request_type');
if (request_type == "bulk_requests") {
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "sc_cart_item");
att.addQuery("sys_created_by", g_user.userName);
//att.addQuery("sys_created_on", '>=', 'javascript:gs.beginningOfLast15Minutes()');
att.query();
if (!att.next()) {
alert("Please attach the requested form before submitting");
return false;
}
return true;
}
}
Thank you
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 09:01 AM
function onSubmit() {
var request_type = g_form.getValue('u_request_type');
if (request_type == "bulk_requests") {
if (this.document.getElementsByClassName('get-attachment').length == 0) {
alert("You must attach Template Document");
return false;
}
If my answer helped you in any way, please then mark it as helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 02:33 AM
Here's the solution you need:
https://community.servicenow.com/community?id=community_article&sys_id=5df1797b1b0c5050fff162c4bd4bcb3f

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 02:42 AM
Hi there,
Earlier today, you posted the same question, though somehow that question is deleted/not visible anymore? I already responded there that you can achieve this with zero code.
Also read about this in this article which I wrote 3 years ago:
- 2019-05-03 Service Portal Catalog Items: Hide Attachment / Mandatory Attachment (Madrid)
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 03:08 AM
Hi,
I did ask the question properly. So, I deleted it and created a new one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 09:01 AM
function onSubmit() {
var request_type = g_form.getValue('u_request_type');
if (request_type == "bulk_requests") {
if (this.document.getElementsByClassName('get-attachment').length == 0) {
alert("You must attach Template Document");
return false;
}
If my answer helped you in any way, please then mark it as helpful.