How to copy an image (jpeg) from sys_attachment to db_image

luca_123
Tera Contributor

Hello guys, I want to copy automatically an image that is uploaded as a record-producer-variable to the image table db_image.

The type of the variable is attachment, so the image is stored in the sys_attachment table.

I tried copying the image with a business-rule, and it (almost) worked.

The image is copied to the image table but i can't open / modify the image.
Also the URL to the image does not work.
any ideas???
Thank you very much!

Script
var imageGr = new GlideRecord("db_image");
imageGr.initialize();
imageGr.name = "test.jpeg";
imageGr.image = current.img;
imageGr.format = "JPEG";
imageGr.insert();

luca_123_2-1667561236167.png

 

luca_123_1-1667560852338.png

 

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

When you add any image into Images manually it also create one record in sys_attachment table, see if the record is created when you copy it using script.

If not then you may need to write image into the attachment table.

This is how it created new image record in attachment when we insert image manually.

AnilLande_0-1667565060758.png

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

2 REPLIES 2

Anil Lande
Kilo Patron

Hi,

When you add any image into Images manually it also create one record in sys_attachment table, see if the record is created when you copy it using script.

If not then you may need to write image into the attachment table.

This is how it created new image record in attachment when we insert image manually.

AnilLande_0-1667565060758.png

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thank you for your tip!
The trick was to update the already existing record in sys_attachment. Change table_name to ZZ_YYdb_image and set the table_sys_id to the corresponding image sys_id in the db_image table.