The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to add at default image to an image field on the Incident form.

mikejkellyuk
Kilo Explorer

I am trying to set a default image in a image field on my incident form when a field on the form is selected.

I have set up a UI policies to display the image field however when the image field displays it asked me to upload an image of search for an image.

I have tried to use the default Value in the dictionary item for that field however this has not worked.

Any help would be gratefully received with this issue.

Kind regards

Michael Kelly

2 REPLIES 2

CapaJC
ServiceNow Employee
ServiceNow Employee

This probably won't be as easy as you think it should be 🙂

Images stored in image fields are actually stored as an attachment to the current record. To see what I mean, put an image in the field, then go to your sys_attachment table. (type sys_attachment.list in the nav filter)

Find the most recently created attachment. The "File name" will be the name of the field (e.g., u_my_image_field), and "Table name" will be ZZ_YY plus the name of the table (e.g., ZZ_YYincident). "Table sys ID" will be the sys_id of the original record.

So to populate that field with a script, you're essentially going to have to copy an attachment from another existing record (that already has the image you want) to the current one. There is a line of script that will copy ALL attachments from one table/sys_id to another (http://wiki.servicenow.com/index.php?title=Copy_Attachments_from_Record_to_Record), so the other record should have only one image field populated.

You can do this in a Business Rule (this is Calgary release script), where the 2nd parameter is the sys_id of the Incident that already has a copy of the image you want to use (you can query for that sys_id, or you can hardcode it), and the 4th is the sys_id of the current record:



GlideSysAttachment.copy("ZZ_YYincident", "62826bf03710200044e0bfc8bcbe5df1", "ZZ_YYincident", current.sys_id);


As the wiki article states, pre-Calgary you need to replace GlideSysAttachment with Packages.com.glide.ui.SysAttachment


mikejkellyuk
Kilo Explorer

I have done what you advised and it works very well.

Thanks for all your help.

Michael