How to clear File Attachment type field in client script?

Pranshu3
Tera Expert

Hi all,

I have a 'File Attachment' type field on Demand table. Now, on the form, this field is dependent on another field.

If the choice option for 'Need attachment?' field is selected as 'Yes', the 'File Attachment' field is visible and a file can be attached to the field, but onChange of 'Need attachment?' field choice to 'No', 'File Attachment' field should disappear as well as the attachment should be removed.

How to remove the attachment on 'File Attachment' field in onChange client script of 'Need attachment?' field ??

Thanks all!

1 ACCEPTED SOLUTION

Hi Ankur,

Along with not displaying the 'File Attachment' field, I am willing to remove the attached file as well, so that on re-display on the field, it comes blank.

The solution found : GlideAjax from Client Script, in script include, GlideRecord sys_attachment table and removed the latest file related to that table record. Though this is not a completely accurate procedure, but a feasible workaround.

Hope others can put in better solution!

View solution in original post

5 REPLIES 5

Omkar Mone
Mega Sage

Hi 

Instead of client script try it with Ui Policy.

Still didn't work.

Issues with 'File Attachment' field, it seems.

Hi Pranshu,

It seems that field type is having an issue in Madrid some patch

UI policies doesn't seem to work on that type of field

the below line of code works for me in 

g_form.setDisplay('u_sample_file', false);

Can you share your script here?

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Along with not displaying the 'File Attachment' field, I am willing to remove the attached file as well, so that on re-display on the field, it comes blank.

The solution found : GlideAjax from Client Script, in script include, GlideRecord sys_attachment table and removed the latest file related to that table record. Though this is not a completely accurate procedure, but a feasible workaround.

Hope others can put in better solution!