Make Attachment mandatory in WS form

armanoj
Mega Sage

Hi ,

 

Make the attachment mandatory in the UI action button , when the button click , check attachment if there is no attachment then make attachment mandatory to submit that form.

6 REPLIES 6

Rakesh_M
Tera Guru

Hi @armanoj ,
add these lines to your ui action

if(current.hasAttachments() != true){

gs.addInfoMessage("PLease add an attachment");

current.setAbortAction(true);

}

refer:https://www.servicenow.com/community/csm-forum/make-attachment-mandatory-in-incident-form/m-p/435070....

Ankur Bawiskar
Tera Patron

@armanoj 

which UI button? where native or workspace or this is catalog form?

share some screenshots

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

Tanushree Maiti
Kilo Patron

Hi @armanoj 

 

You can meet this requirement by using a combination of a UI Action + a Business Rule.

 

Step 1: Add the following script to your specific  UI Action . Sample step is on Close Ui Action.

 

(function executeCloseUIAction() {

if (!g_form.hasAttachments()) {
alert("Please attach a file before closing the task.");
return false;
} else {
g_form.setValue('state', 'closed'); // Modify the state value as per your requitement
g_form.save();
}

})();
 

 

Step 2: Configure BR

  • When: Before
  • Insert: true
  • Update: true
  • Condition: State changes to Closed

In the Script section, include:

 
(function executeRule(current, previous /* null when async */) {

if (current.state == 'closed' && !current.hasAttachments()) {
gs.addErrorMessage('Please attach a file before closing the task.');
current.setAbortAction(true);
}

})(current, previous);
 
 
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

armanoj
Mega Sage

@Ankur Bawiskar @Rakesh_M ,

onclick () button action