Retrieve Image from db_image record

HrithikN
Tera Contributor

Hi Everyone,

 

I have a use case to retrieve the Image content of db_image table record.

 

We usually have a image field in db_image record where our uploaded image is stored.

 

Using the below script I tried retrieving the same image but the response is empty:

 

var grImage=new GlideRecord('db_image');
if(grImage.get('687fa131eb1301003eadeb29a206fe05'))
{
gs.info(grImage.image);
}

Could someone please help me in getting the uploaded image? I have to add it to an outgoing email text as signature.
 
Regards,
Hrithik.
1 ACCEPTED SOLUTION

Voona Rohila
Mega Patron
Mega Patron

Hi @HrithikN 

There are 2 ways to do it

First way - 

Open that particular image and you will see a html code with path that's available.

Follow below steps 

Copy below highlighted part

VoonaRohila_0-1758894862447.png

In your notification, click on 'source code' icon and paste the content - The image will be attached.

VoonaRohila_1-1758895024538.pngVoonaRohila_2-1758895040459.png

Second Way : 

Click on the Image icon in your notification and give the Name of the db_image record( see screenshot below)

VoonaRohila_3-1758895124341.png

Third Way : 

If you want to achieve this with email script then use below logic

var grDbImage = new GlideRecord('db_image');
    if (grDbImage.get('687fa131eb1301003eadeb29a206fe05')) {
        //  gs.info('image: ' + grDbImage.getValue('name'));

        template.print('<img src="' + grDbImage.getValue('name') + '" width="300" height="450">');
    }

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

2 REPLIES 2

Voona Rohila
Mega Patron
Mega Patron

Hi @HrithikN 

There are 2 ways to do it

First way - 

Open that particular image and you will see a html code with path that's available.

Follow below steps 

Copy below highlighted part

VoonaRohila_0-1758894862447.png

In your notification, click on 'source code' icon and paste the content - The image will be attached.

VoonaRohila_1-1758895024538.pngVoonaRohila_2-1758895040459.png

Second Way : 

Click on the Image icon in your notification and give the Name of the db_image record( see screenshot below)

VoonaRohila_3-1758895124341.png

Third Way : 

If you want to achieve this with email script then use below logic

var grDbImage = new GlideRecord('db_image');
    if (grDbImage.get('687fa131eb1301003eadeb29a206fe05')) {
        //  gs.info('image: ' + grDbImage.getValue('name'));

        template.print('<img src="' + grDbImage.getValue('name') + '" width="300" height="450">');
    }

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Ankur Bawiskar
Tera Patron
Tera Patron

@HrithikN 

are you using this in email script?

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