Prevent Catalog item Submission if there is no attachment

Chintha Murali
Kilo Expert

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

1 ACCEPTED SOLUTION

Srinivas reddy3
Mega Expert

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.

View solution in original post

4 REPLIES 4

AnirudhKumar
Mega Sage
Mega Sage

Here's the solution you need:

https://community.servicenow.com/community?id=community_article&sys_id=5df1797b1b0c5050fff162c4bd4bcb3f

Mark Roethof
Tera Patron
Tera Patron

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.

find_real_file.png

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

LinkedIn

Hi, 

I did ask the question properly. So, I deleted it and created a new one.

 

Srinivas reddy3
Mega Expert

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.