user_image fields questions - how to read or copy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2012 11:57 AM
If you use a field type of user_image, to display an image directly on a form, how can you query the data in that field?
For example, create a field called screen shot on the incident form, and load a picture into it. Then save it.
g_form.getValue('u_screen_shot') returns null
even doing a glide record query from background scripts will return null:
var gr3 = new GlideRecord('incident');
gr3.addQuery('sys_id','0c82661b2be534c0adf2973a89da1541');
gr3.query();
while (gr3.next()) {
gs.print(gr3.u_number);
gs.print(gr3.u_type);
gs.print(gr3.u_screen_shot);
}
Now, even if I can't see the data in the field, I would still need to copy it to another type of form. Perhaps a change or problem record. Doing a gliderecord query and then doing an insert into another field of the same user_image type also fails.
We cannot use an attachment for this, as the screen shot needs to appear on the form.
We do not want to use an HTML field, as that allows text, etc. It needs to be an image field, one of the standard field types available when you create the field.
Just one further check, the picture does not show up in the sys_attachment table, nor does Packages.com.glide.ui.SysAttachment.copy('sc_req_item', 'sys_id', 'sc_task', 'sys_id'); work at all on an embedded image
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2012 12:14 PM
Images put into user_image fields get stored as attachments in the sys_attachment table where Table name is ZZ_YYtablename (replace tablename with the name of the specific table the field is on), File name is the name of the user_image field, and Table SysID is the sys_id of the record the image is added to. I don't think there's an API for reading, printing, copying them, currently.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2012 12:17 PM
The following let me copy a user_image from one User record to another, though it would have unfortunately also copied any other attachments that happened to be there.
Packages.com.glide.ui.SysAttachment.copy('ZZ_YYsys_user', '62826bf03710200044e0bfc8bcbe5df1', 'ZZ_YYsys_user', '0a826bf03710200044e0bfc8bcbe5d7a');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2012 01:12 PM
Awesome! Works great from a BR, and I created a Glide Ajax call to make it work on client scripts. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2013 11:11 AM
Might be considered a hack, but when I need to put an image field on a table, I'll use a user_image field and then put a business rule on the attachment table to push back the sys_id of the attachment to the field itself..
So.. let's say I have a new field called u_logo on the table... I will write a business rule on the sys_attachment table to trigger on insert when current.file_name == 'u_logo'... I simply then query the record in the source table using table_sys_id and actually store the sys_id of the image attachment in the same field... so u_logo actually ends up holding a value (even though the user_image field type doesnt seem to use anything that is actually stored...)
setImageFilePath();
function setImageFilePath(){
var gr = new GlideRecord('core_company');
gr.get(current.table_sys_id);
gr.u_company_logo = current.sys_id;
gr.update();
}
This also allows me to easily generate a URL to the image file on the fly: https://instance.service-now.com/%u_logo%.iix