We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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.

8 REPLIES 8

Rakesh_M
Mega Sage

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
Tera 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 Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

armanoj
Mega Sage

@Ankur Bawiskar @Rakesh_M ,

onclick () button action