Make attachment mandatory when check box is selected

Raghavendra
Tera Expert

Hi all,

 

I have one catalog item and it has one variable called "has_approval" and its type is "checkbox". If any user selects that checkbox, then the attachment should be mandatory. If the user selects the check box and if he didn't attach the attachment, then a pop up should show like "Please attach the attachment".

 

Can you please tell me how we should write the script.

 

Thank you

1 ACCEPTED SOLUTION

Hi @Raghavendra ,

                                    Please refer this thread it may help you. Verify Mandatory Attachments Count on Catalog Item 

Kindly mark correct and helpful if Applicable

View solution in original post

9 REPLIES 9

Brad Bowman
Kilo Patron
Kilo Patron

I would suggest adding a variable with the type of Attachment to your Catalog Item, then with a simple UI Policy you can make this variable mandatory when the checkbox value = true.  This is the simplest approach and works both in the native UI / Service Catalog and the Service Portal.  Here is an article detailing the other ways to make an attachment mandatory

https://www.servicenow.com/community/developer-articles/possible-ways-for-making-an-attachment-manda... 

SatyakiBose
Mega Sage

Basheer
Mega Sage

Hi @Raghavendra ,

You can write an OnSubmit Client script and use below code

function onSubmit() {
var attachment = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('There is no attachment');
return false;
}
Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

@ basheer

Hi

Thanks for tyour reply,I tried with your code but when i click on the check box and submit the catalog item.I'm getting the below error.

onSubmit script error: TypeError: Cannot read properties of null (reading 'getElementById'):
function () { [native code] }

I'm attaching the screen shot of the error