Validate attachments on a record producer

amadosierra
Kilo Guru

I need to validate if the user has attached at least one document in a record producer and I'm trying to use the following function in the onSubmit Client Script but id doesn't work. I'm using the same function in the form itself and it works there.

 

The call to getUniqueValue() does not return anything. Does anybody knows what applies in this case?

 

function validateAttachments() {
   var sid = g_form.getUniqueValue();
   var gr = new GlideRecord('sys_attachment');

   alert(sid);

   return gr.get('table_sys_id', sid);
}

 

Regards,

 

/Amado Sierra

6 REPLIES 6

Hi Amado,



You can get the sys_id of the record producer using gel('sysparm_id').value.



Regards,


Solutioner


Thanks everybody for your help. I have compiled the couple of functions that worked for my purpose, based on the proposed solutions.



Here is the function I ended up using:


function validateAttachments() {


  var sid = gel('sysparm_item_guid').value;


  var gr = new GlideRecord('sys_attachment');


gr.addQuery('table_sys_id', sid);



  if (gr.next())


        return true;



  return false;


}



And here's an alternative solution that works, without retrieving the record producer's id:



function validateAttachments() {


  var attachments = document.getElementById('header_attachment_list_label');



  if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {


      alert('You must attach at least 1 file before submitting this request.');


      return false;


  }



  return true;


}