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.

Copy image field from one form field to order record form field via script ...

Zod
Giga Guru

HI,

I'm using a ui action and use current record information to create a new record. The initial form includes an image field and I'd like to copy the image to the new field ... 

....

gr.u_new_image_field = current.u_image_field; does not work for image fields .. is there an easy way to do that?

1 ACCEPTED SOLUTION

var ids = GlideSysAttachment.copy('ZZ_YYsc_cat_item','current.sys_id','ZZ_YYsc_cat_item','destinationsys_id');

var gr = new GlideRecord("sys_attachment");
gr.addQuery("sysid", ids);
gr.query();
if (gr.next()) {
gr.setValue('file_name', 'u_icon.jpg');
gr.update();
}

View solution in original post

16 REPLIES 16

This looks like it could work - IF both fields would be called the same 😉

Unfortunately the don't. One is u_icon (source).. the other is icon (target) ... any why to manipulate this easily?

I manged it ... with renaming it again afterwards ... but does not look like a good programming method 😉

Please tell me if you have a way to put it right from the beginning ..

thank you!

var ids = GlideSysAttachment.copy('ZZ_YYsc_cat_item','current.sys_id','ZZ_YYsc_cat_item','destinationsys_id');

var gr = new GlideRecord("sys_attachment");
gr.addQuery("sysid", ids);
gr.query();
if (gr.next()) {
gr.setValue('file_name', 'u_icon.jpg');
gr.update();
}

yeah. ok.

Did it nearly like this.

Somehow still not nice but it works.

Thanks a lot!!

Strange that SN does not provide more easy functions OOB ... 

Oleg
Mega Sage

Try copy method of GlideSysAttachment. See here. It seems to me exactly what you need.