Need to add the attachment validation

vinuth v
Tera Expert

Hi All,

I am working on the one of the form, in this form I need to restrict the form submission when "Are you able to browse wireless network. If Yes attach screenshot." and " Do you get any error message? If Yes attach screenshot." both the variables is Yes, if the use is not attached the screen shot I need to populate the alert message and need to restrict the form submission.

 

I wrote the onSubmit client script but it is not working as expected.

function onSubmit() {
   //Type appropriate comment here, and begin script below
  var h = g_form.getValue('are_you_able_to_browse_1');
  var b = g_form.getValue('do_you_get_any_error_1');
   if(h =='Yes' && b == 'Yes'){
    var hasAttatchment = g_form.hasAttatchment;
    if(!hasAttatchment){
        alert("Kindly attach the screenshot to support investigation");
        return false;
    }
   }
   return true;
}
 
Thanks in advance,
Vinuth
2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@vinuth v Please refer to this tutorial to make attachment mandatory on the catalog item form https://www.basicoservicenowlearning.in/2020/10/attachment-mandatory.html

 

Hope this helps.

AmenaA
Giga Guru

Hello @vinuth v ,

 

The following Client Script would work for a catalog item on Native UI & Service Portal:

 

TYPE: onSubmit

UI Type: All

Isolate Script: False

Script:

function onSubmit() {

 

var cat_id = g_form.getValue('sysparm_item_guid');

var gr = new GlideRecord("sys_attachment");

gr.addQuery("table_name", "sc_cart_item");

gr.addQuery("table_sys_id", cat_id);

gr.query();

if (!gr.next()) {

          alert("You must add an attachment before submitting this request.");

          return false;

         }

}

 

The above code restricts the form submission if there's no attached attachment.

Please add conditions as needed.

 

Thanks,

A. A. B