Attachment mandatory in change request

svizcaino
Kilo Contributor

Hi guys, i was wondering if someone can gave me some advice of how to make mandatory the attachments before the submit in the change request form. Thanks in advance

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Try an onSubmit client script. Something like this:



function onSubmit(){  


  var attachment = new GlideRecord('sys_attachment');      


 


  attachment.addQuery('table_name','change_request');  


  attachment.addQuery('table_sys_id',current.sys_id);      


  attachment.query();  


 


  if(!attachment.next()){      


      alert ("Please include attachment");      


  return false;


  }


}



Cheers,



Tim


View solution in original post

7 REPLIES 7

Community Alums
Not applicable

Try an onSubmit client script. Something like this:



function onSubmit(){  


  var attachment = new GlideRecord('sys_attachment');      


 


  attachment.addQuery('table_name','change_request');  


  attachment.addQuery('table_sys_id',current.sys_id);      


  attachment.query();  


 


  if(!attachment.next()){      


      alert ("Please include attachment");      


  return false;


  }


}



Cheers,



Tim


was very useful Tim!!!


just one thing... current is running on the server side, i just need to change that to work in the client side.



this one works for me...



function onSubmit(){  


  var attachment = new GlideRecord('sys_attachment');      


 


  attachment.addQuery('table_name','change_request');  


  attachment.addQuery('table_sys_id', g_form.getUniqueValue());


  attachment.query();  


 


  if(!attachment.next()){      


      alert ("Please include attachment");      


  return false;


  }


}


Community Alums
Not applicable

Glad it helped! Yes, your method for sure makes more sense.



It's not considered best practice to use GlideRecord in a client script, so a GlideAjax call would be best when using client script. The other option, which may be even better, as it's less code, and all server side, is the before business rule mentioned in the other two replies on this post.



Cheers,



Tim


GlideRecord is working in client script?