Attachment validation on catalog item on submit

Devi16
Tera Contributor

Hi Community,

I have some requirement like I have to check and validate something on attachment.

While submitting catalog item I have to check, user attached the attachment or not, if yes need to validate right attachment or not and, if yes, I need to check that attachment has 50 records or less than 50 records in that.

we have some field on the catalog form like attachment, it holds (true/false) values.

 

5 REPLIES 5

Mark Roethof
Tera Patron
Tera Patron

Hi there,

If it's just about if there is a Attachment, since a few releases this is out-of-the-box available:
Service Portal Catalog Items: Hide Attachment / Mandatory Attachment [Madrid]

About your question concerning if that attachment has x records, I don't have a solution/idea on that.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So based on variable of type true/false you need to validate attachment is present or not

please explain in detail

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Rdevi 

if you want to validate attachment is present or not based on the true/false variable then below is the script

Example: if attachment variable is true then attachment is mandatory something like this

Script: onSubmit

Note: Ensure Isolate Script field is set to False for this Catalog Client Script to ensure DOM manipulation works

function onSubmit() {
    //Type appropriate comment here, and begin script below

// give your variable name here

if(g_form.getValue('attachment').toString() == 'true'){

var countRequired = 1;
    if(window == null){
        // portal
        if(this.document.getElementsByClassName('get-attachment').length != countRequired) {
            alert('You must add attachment before submitting this request.');
            return false;
        }
    }
    else{
        // native view
         var length = $j("li.attachment_list_items").find("span").length;
        if(length != countRequired){
            alert('You must add attachment before submitting this request.');
            return false;
        }
    }
}

}

Isolate Script: Set to False

image

Regards
Ankur

 

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Based on true or false variable, I need to validate attachment is there or not before submitting the form, if attachment is not there form should not be submitting and put some alert, if attachment there, validate that attachment is right one or not (we are providing some template, user has to use that template only), if user not uploading that right template need to put some alert message, and if right template user uploading, check how many record in that (limit 50).