attachment fails

tGhadage
Tera Contributor

Hi Guys,

 

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

    // Add your code here
   var attachment_file = new GlideRecord('sys_attachment');
   //attachment_file.addAggregate('COUNT');
   //attachment_file.addQuery('table_name',current.getTableName());
   attachment_file.addQuery('table_sys_id',current.sys_id);
   attachment_file.query();
   //
   
   while(attachment_file.hasNext()){
   gs.addErrorMessage('Please attach the requried documents before closing the task');
   current.state=previous.state;
   current.setAbortAction(true);
}
})(current, previous); 
 
using this code i am trying to make attachment mandatory but even when i attach the attachment still its not getting close complete.
 
thanks!! 
please help this out.