How to attach image through import set to existing record

Eswaree devi S
Tera Contributor

Hi All,

 

I do have a photo.i converted that to base 64 and pasted base 64 data into excel.it is not getting attached to the record.

 

I am able to attach CSV and text file through import set to record but not png file.

 

here is the on after script that i wrote for CSV and Text file.

 

 if (source.u_base64_data) {
        var gsu = new GlideStringUtil();
        var attachment = new GlideSysAttachment();
        try {
            var decodedbytes = gsu.base64DecodeAsBytes(source.u_base64_data);
            attachment.write(target, source.u_file_name, source.u_content_type, decodedbytes);
            gs.info('attchment is' + source.u_file_name + "added to the incident" + target.number);
        } catch (error) {
            gs.error('attchment is' + source.u_file_name + "added to the incident" + target.number + error);

        }
    }
 
1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Eswaree devi S 

you are in global scope or scoped app?

if you are in global scope then this should work fine

 if (source.u_base64_data) {
        try {
var ecc = new GlideRecord('ecc_queue');
ecc.initialize();
ecc.agent = "AttachmentCreator";
ecc.topic = "AttachmentCreator";
ecc.name = source.u_file_name + ":" + source.u_content_type;
ecc.source = "tableName:" + target.sys_id; // give your table name here
ecc.payload = source.u_base64_data;
ecc.insert();
        } catch (error) {
            gs.error('attchment is' + source.u_file_name + "added to the incident" + target.number + error);

        }
    }

If my response helped please mark it correct and close the thread so that it benefits future readers.

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