We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How do I make the attachment field mandatory in Service Portal or Employee Center?

anamariatam
Tera Contributor

 

Hello, I just wanted to contribute by sharing how to make an attachment mandatory in ServiceNow when, for some reason, you can’t use the default “Mandatory attachment” button on the catalog item. I found a very simple way to do it and wanted to share it since there isn’t a place in the Community that gets straight to the point.

1. Create a Catalog Client Script

2. Required things to fill in:

  • Type: OnSubmit
    (We do it in OnSubmit because this will prevent the user from submitting the form until they attach something.)

Only select Applies on a Catalog Item view. If you select Applies on Requested Item and Catalog Task, it will cause an error, especially if the user removes the attachment.

In the script, copy this:

 

 
function onSubmit() { if (this.document.getElementsByClassName('get-attachment').length == 0) { g_form.addErrorMessage('please attach something'); return false; } }
-----------------------------------------------------------------------------------------------------------------------------------------------
 

g_form.addErrorMessage('please attach something');

 

This part of the code will show a default ServiceNow alert, informing the user that they cannot submit anything until an attachment is added:

And that’s it — it’s that simple.

Greetings from Colombia

 

3 REPLIES 3

Nayan ArchX
Tera Guru

Hi,

 

If it is a Catalog item

 - go to the maintain item --> Catalog item

- Create a UI policy 

- Make the variable field mandatory.

 

 

Ankur Bawiskar
Tera Patron

@anamariatam 

why you can't use "Mandatory Attachment" checkbox for portal?

Your requirement can be achieved without scripting

Simply enable that checkbox

AnkurBawiskar_0-1771213547351.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

SohamTipnis
Kilo Sage

Hi @anamariatam,

 

There is a mandatory attachment checkbox option in portal settings; you can select that.

 

If you find my answer useful, please mark it as Helpful and Correct ‌😊


Regards,
Soham Tipnis
ServiceNow Developer ||  Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10