I am actually getting an issue while converting the image into base64 encoded string. Please help

a41022639
Tera Contributor

I am trying to convert the image into base 64 encoded string, can anyone help me in this.

1 ACCEPTED SOLUTION

Abhishek_Thakur
Mega Sage

Hi @a41022639 ,

 

You can go through this link, I have already posted a script include code.

https://www.servicenow.com/community/developer-forum/servicenow-script-to-convert-the-image-into-bas...

 

Please accept my solution and give thumbs up, if it helps you.

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

HI @a41022639 

I am not sure of the exact scenario you are trying to encode in-

Below is the function to convert a image into base64-

 

(function() {
    var sysId = '6816f79cc0a8016401c5a33be04be441'; // sys_id of the user record
    var tableName = 'sys_user'; // Table name


            // Now update the base64Value field with this base64 string
            var userRecord = new GlideRecord(tableName);
            if (userRecord.get(sysId)) {
				var base64Image = GlideStringUtil.base64Encode(userRecord.photo);
               userRecord.setValue('base64Value', base64Image);
                userRecord.update();
                gs.info('Base64 value updated for user: ' + base64Image);
            }


})();

 

Here i have taken sys_user as a table where photo is stored against a profile.
i am converting it and storing in a separate field.

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

Thanks & Regards,

 

Sanjay Kumar Gupta

Abhishek_Thakur
Mega Sage

Hi @a41022639 ,

 

You can go through this link, I have already posted a script include code.

https://www.servicenow.com/community/developer-forum/servicenow-script-to-convert-the-image-into-bas...

 

Please accept my solution and give thumbs up, if it helps you.