Inserting images into an HTML field attaches the images to the current record table

jobin1
Tera Expert

Hi All,
Inserting images into an HTML field attaches the images to the current record table,how to restrict this behavior
Regards,

Jobin 

1 REPLY 1

Anil Lande
Kilo Patron

Hi,

You can create a After Insert business rule on sys_attachment table that should run only for your custom table.

You can add below script:

(function executeRule(current, previous /*null when async*/ ) {
    var recordId = current.table_sys_id;
    var fileName = current.file_name;
    var attachmentid = current.sys_id;
    var grVar = new GlideRecord('table_name'); // replace your table name here
    grVar.addQuery('sys_id', recordId);
    grVar.query();
    if (grVar.next()) {        
        var attachImage = '<p><img src="/sys_attachment.do?sys_id=' + attachmentid + '"/></p>';
        grVar.u_html_field = attachImage;
        grVar.update();
    }

})(current, previous);

 

Make sure your BR only runs for your table and attachment is of type image (use correct when to run condition to avoid running it for other type of records)

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande