writeBase64 returning undefined

Mahesh23
Mega Sage

Hello,
I am trying to add attachment using Base64 but the output is not expected. its showing corrupted image. what could be the issue ?
Actual Image 

Mahesh23_1-1667318855172.png


Output

Mahesh23_0-1667318818616.png

 

 

var data = 'AwAUADC39lhI/wBWMUfZIP8AnkKsUUAV/skH/PIUfZIP+eIqLU3ARFyck54p2nhhEwYEEN3PtTAk+zRf88xTTaQ84jwfUVZoPSkAUUlFADJY0kA3qDj1pYkWNcKMClbpQvSgB1Hako7UAf/Z';
var attachment = new GlideSysAttachment();

var rec = new GlideRecord('incident');
var incidentSysID = '4a05c6bedb72d510cb58b7e8f49619a9';
rec.get(incidentSysID);
var fileName = 'example.png';
var contentType = 'image/png';
//var base64Encodedcontent = 'SSBhbSB0ZXh0Lg==';

var agr = attachment.writeBase64(rec, fileName, contentType, data);

gs.info('The attachment sys_id is: ' + agr);

 

 

 

 

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

That fails in the Global application scope. It worked for me when I ran that in Scripts Background in application scope I have there. See:

 

GlideSysAttachmentScopedAPI 

View solution in original post

4 REPLIES 4

Bert_c1
Kilo Patron

That fails in the Global application scope. It worked for me when I ran that in Scripts Background in application scope I have there. See:

 

GlideSysAttachmentScopedAPI 

shiven
Tera Contributor

I think, there is still an issue where document is generated but its corrupted file.

If one open the attachment, it will give error to open.

 

did you find an issue? I'm generating image, but it's corrupted also

smitdhruve-
Tera Contributor

I am facing similar issue.
Any workaround?
Is this issue fixed?