- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 02:40 PM
Hi,
I have a custom table with office equipment records. I want to update the records with an image. How can I do that via a script since it is way to many records to do manually? Below is the scripting I have tried but with no success.
var count = 0;
var pic = new GlideRecord('db_image');
var gr = new GlideRecord("u_office_equipment");
gr.addQuery('u_display_name=AIR CONDITIONER, PORTABLE');
gr.query();
while(gr.next()){
if(pic.get('fe3880b5c3022100910900251eba8f72')){
//gr.u_image = '';
//gr.u_image = 'fe3880b5c3022100910900251eba8f72'; //sys_id of db_image record
gr.u_image = pic.getDisplayValue('image');
count++;
gr.update();
}
}
gs.log('Done. Updating ' + count + ' records.');
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 05:04 PM
Jared in my first response I tried to use your script and perform the job which you were trying to do.
The link which I provided has the solution of OOB functionality of copying the attachment from one record to another.
So, with the help of the provided link I came upto a workaround for you, You need to attach the image to one record manually and then you can run the below script and all the attachments of the manually updated record will be copied to the others.
var count = 0;
var gr = new GlideRecord("u_office_equipment");
gr.addQuery('u_display_name=AIR CONDITIONER', 'PORTABLE');
gr.addQuery('sys_id', '!=', '551cc707db891010996e6a4948961997');
gr.query();
while (gr.next()) {
GlideSysAttachment.copy("u_office_equipment", "551cc707db891010996e6a4948961997", "u_office_equipment", gr.sys_id.toString());
count++;
}
gs.log('Done. Updating ' + count + ' records.');
Replace 551cc707db891010996e6a4948961997 with the sys id of the record which is manually updated.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0720062
Note:- Including the field image other attachments will also be copied with the above script (GlideSysAttachment.copy("ZZ_YYincident", "<Table sys ID>", "ZZ_YYincident", current.sys_id);).
Kindly mark my answer as Correct and helpful based on the Impact.
Regards,
Alok

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 03:20 PM
Below link would be helpful for you
How to assign Image in db_Image table to an Image field type?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 03:47 PM
Thanks for your response Alok. I tried your code and now the output in my image field is '

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2020 05:04 PM
Jared in my first response I tried to use your script and perform the job which you were trying to do.
The link which I provided has the solution of OOB functionality of copying the attachment from one record to another.
So, with the help of the provided link I came upto a workaround for you, You need to attach the image to one record manually and then you can run the below script and all the attachments of the manually updated record will be copied to the others.
var count = 0;
var gr = new GlideRecord("u_office_equipment");
gr.addQuery('u_display_name=AIR CONDITIONER', 'PORTABLE');
gr.addQuery('sys_id', '!=', '551cc707db891010996e6a4948961997');
gr.query();
while (gr.next()) {
GlideSysAttachment.copy("u_office_equipment", "551cc707db891010996e6a4948961997", "u_office_equipment", gr.sys_id.toString());
count++;
}
gs.log('Done. Updating ' + count + ' records.');
Replace 551cc707db891010996e6a4948961997 with the sys id of the record which is manually updated.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0720062
Note:- Including the field image other attachments will also be copied with the above script (GlideSysAttachment.copy("ZZ_YYincident", "<Table sys ID>", "ZZ_YYincident", current.sys_id);).
Kindly mark my answer as Correct and helpful based on the Impact.
Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2020 11:52 AM
Thank you Alok! That script and the HI article you linked solved it for me and helped me to understand what was happening.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2024 11:59 PM
Hi.
Instead of taking the image from "db_image" to insert in any record, can we insert the image directly from PC through scripting. Is it possible?
Regards,
RAJU MANGA