Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help with writeBase64 in GlideSysAttachment

Abhijit Das7
Tera Expert

Hi Everyone,

 

I am trying to send base64 image as attachment to sys_cs_collab_chat table using GlideSysAttachment , but it not attaching and not even returning any error.

 

Scripted Rest API:

 

 

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    // implement resource here

    var requestBody = request.body.dataString;
    var parser = new global.JSON();
    var parsedData = parser.decode(requestBody);
    var imageName = parsedData.imageName;
    var imageType = "image/jpeg"; 
    var imageValue = parsedData.imageValue;
    var table = parsedData.object_name;
    var sysId = parsedData.object_id;
   
    var rec = new GlideRecord(table);
    rec.addQuery('sys_id', sysId);
    rec.query();
    if (rec.next()) {
        if (imageName && imageValue && imageType != '') {
            var sa = new GlideSysAttachment();
            sa.writeBase64(rec, imageName, imageType, imageValue);
        }         
    }
})(request, response);

 

 

 

JSON payload;

{"object_id":"ea09239a97d00290c0ebd404a253af08",
"imageName":"QjjeAKNbCwNoJwEKrg1dObUx.jpg",
"imageValue":"<<base64FileContent>>",
"object_name":"sys_cs_collab_chat"}

 

Can anyone point out my mistake. 

 

cc: @Ankur Bawiskar 

 

Thanks in advance.

 

11 REPLIES 11

@Abhijit Das7 

did you check in sys_attachment it came fine?

When you download the image from sys_attachment is it a proper one or a corrupted one?

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

Hi @Ankur Bawiskar,

 

yes, it came fine sys_attachment. I am able to download and I can see it. It is fine.

 

Thanks

@Abhijit Das7 

then definitely it's something when you view it in sidebar

can you share screenshot where are you willing to see this?

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

Hi @Ankur Bawiskar 

 

I want the image(attachment) to be visible in sidebar chat as it is there in below image. But that image I have added manually.

I want to make image(attachment) using Scripted Rest API inside sidebar chat. I am able to send text inside sidebar chat using Scripted Rest API, but image is not coming

 

sidebar2.png

 

Thanks

@Abhijit Das7 

possibly it won't be direct.

Did you check when you add image manually how it's stored?

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