The CreatorCon Call for Content is officially open! Get started here.

attachment needs to mandatory

Satya kolisetti
Tera Contributor

Hi All, 

 

Can anyone help me, how to achieve the below requirement.

 

when we select the 'No' in yes/No type variable in catalog item then attachment needs to mandatory.

 

Attached the reference screenshot.

 

Thanks in advance,

Satya

1 ACCEPTED SOLUTION

Jean-Emmanuel
Tera Guru

Hello you can create an on-submit client script to check if there is more than 1 attachment when the request is submitted or not.

Here is a sample:

 

function onSubmit() {
    var answer =true;
  if (g_form.getValue('your_field') == 'no')
{
    
    if(this.document.getElementsByClassName('file-list-wrap').length == 0) {
 g_form.addErrorMessage('PLEASE ATTACH THE REQUIRED FILE ');
        answer= false;
    } 
    }
return answer;
}

 

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Satya kolisetti 

 

https://www.servicenow.com/community/developer-forum/how-to-make-attachment-mandatory-based-on-condi...

 

This might be helpful.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Sohail Khilji
Kilo Patron

Hi @Satya kolisetti ,

 

Try this code :

 

if (g_form.getValue('<yourfiled>') == 'no' && !(g_form.getAttachment().length == 0)) {
alert("Please attach the attachment");
return false;
}
return true;

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Jean-Emmanuel
Tera Guru

Hello you can create an on-submit client script to check if there is more than 1 attachment when the request is submitted or not.

Here is a sample:

 

function onSubmit() {
    var answer =true;
  if (g_form.getValue('your_field') == 'no')
{
    
    if(this.document.getElementsByClassName('file-list-wrap').length == 0) {
 g_form.addErrorMessage('PLEASE ATTACH THE REQUIRED FILE ');
        answer= false;
    } 
    }
return answer;
}