How to Copy One image(Field 1) to another image(Field 2) both fields are of Image type

alekhyanagabhyr
Kilo Contributor

HI Everyone,

I have a requirement where I have to copy one image field value to another field as follows:

-- I have inserted image in "db_image" table this image stored in image field(FIELD 1) in that record.

-- I have another image type field FIELD2 in catalog task table

So I want to display image of FIELD1 to FIELD2.

Thanks,

Alekhya N

9 REPLIES 9

Chuck Tomasi
Tera Patron

Image fields store their content as attachments. You'll need to use the standard attachment copy method to attach it to the right record and field.



http://wiki.servicenow.com/index.php?title=Copy_Attachments_from_Record_to_Record#gsc.tab=0



You have to use that ZZ_YYtablename format for the table name on image fields or it will be attached like a standard attachment at the top. If you have two fields, attach an image in both and then go to sys_attachment to find out what the table_name is for both fields. I've never used a form with two image fields so I don't know how it differentiates the two.



Ultimately, it is going to come down to the GlideSysAttachment.copy() method. http://wiki.servicenow.com/index.php?title=Copy_Attachments_from_Record_to_Record#gsc.tab=0


find_real_file.png


HI alekhya As images are stored as attachments you can write BR in catalog task table to copy attachment from db_image table. (function executeRule(current, previous /*null when async*/) { GlideSysAttachment.copy("db_image", sysid of current record, "sc_task", current.sys_id); })(current, previous);


Hi ctomasi your response is very useful, thanks!


I just have one more quick question...


Can two Image fields point to the same attachment? (That way, we could save some disk space and make image field point to the same attachment)



Thanks


Hi Eduardo,



Images and image fields are one to one relationships. You cannot have multiple references to the same image at this time. For what it's worth, you really don't need to worry too much about disk space with a cloud implementation - we don't charge you by the amount of storage you use. That's not to say you shouldn't be thinking about it, only that you needn't be concerned.



I like the idea of multiple references to a single attachment. I invite you to open an enhancement request! Our product managers DO listen.


Enhancement requests: Tell us how you would improve the ServiceNow product