Restrict Attachments in Catalog Item

harshi_ramesh
Tera Expert

Hi All

Had a query regarding 'Add Attachment'. We need to restrict user from submitting form if more than 3 attachments are submitted. 

My queries:

  • Can we use the OOB Add Attachment for this case? How?
  • Tried enabling 'Hide Attachment' checkbox and created a variable of type 'Attachment'. Wrote a Catalog Client Script to check length and throw error message. But in form itself after uploading one attachment, second attachment cannot be added. 'Updating the attachment will delete the previous attachment permanently. Do you want to continue?' getting this error.

Please help with some solution.

Thanks!!

#catalog

2 ACCEPTED SOLUTIONS

@harshi_ramesh 

yes it's a standard message which is shown.

The script I shared should work fine in both native + portal.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

Hi 
Thanks for the help! 
Just tried the code, with a bit of tweak. Changed a bit and it worked.

Sharing below

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var getAttach = this.document.getElementsByClassName('get-attachment').length;
    //alert(getAttach+"length is");
    if (getAttach > 3) {
        g_form.addErrorMessage("Maximum number of attachment is 3");
        return false;
    }
}

Thanks @Ankur Bawiskar 

Cheers

View solution in original post

6 REPLIES 6

@harshi_ramesh 

Glad to know.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@harshi_ramesh 

Seems you marked your own response as correct.

Would you mind marking my response as correct as my script worked for you?

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