- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 06:33 PM
I am trying to dynamically add attachments to every imported record and want to automatically attach it to the image prompt, I tried a script but I cannot seem to make the image display properly work..
I have tried this script:
This is what it shows up:
Its not an image as there is no preview for it. I'm not sure why it is not showing the image.
I wanted to display the images just like the other image(note that I manually added the image, but I wanted to dynamically add it base on my script) in the pic below but its not showing it properly.
For reference this is my imported excel table.
Here is my mapped fields:
Can anyone please help? It's been a few days and I am still unfortunately stuck.
Solved! Go to Solution.
- Labels:
-
Studio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:09 PM
Hi,
This worked for me
Remove line 10 i.e. don't copy
Add these lines as you are removing line 10
Give correct name of image field from target table.
I assume you are loading images only into the target table from import set.
var attachmentRecord = new GlideRecord("sys_attachment");
attachmentRecord.orderByDesc("sys_created_on");
attachmentRecord.addQuery("table_name", target.sys_class_name);
attachmentRecord.addQuery("table_sys_id", target.sys_id);
attachmentRecord.addQuery("file_name", fileName);
attachmentRecord.query();
if(attachmentRecord.next()){
var sysId = new global.VariableUtil().copyAttachment(attachmentRecord.getUniqueValue(), "ZZ_YY" + target.sys_class_name, target.sys_id);
target.u_imageFieldName = sysId; // give your field name which holds image
target.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:09 PM
Hi,
This worked for me
Remove line 10 i.e. don't copy
Add these lines as you are removing line 10
Give correct name of image field from target table.
I assume you are loading images only into the target table from import set.
var attachmentRecord = new GlideRecord("sys_attachment");
attachmentRecord.orderByDesc("sys_created_on");
attachmentRecord.addQuery("table_name", target.sys_class_name);
attachmentRecord.addQuery("table_sys_id", target.sys_id);
attachmentRecord.addQuery("file_name", fileName);
attachmentRecord.query();
if(attachmentRecord.next()){
var sysId = new global.VariableUtil().copyAttachment(attachmentRecord.getUniqueValue(), "ZZ_YY" + target.sys_class_name, target.sys_id);
target.u_imageFieldName = sysId; // give your field name which holds image
target.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:26 PM
Hello Ankur,
Yes, I am loading images based from an import set.
I really apologize for taking up your time, but unfortunately it is still not working in my side.
For references I'll show my configs:
This is the target table.
This is the image field:
This is the config for the transform map
and finally the updated script as you have instructed me to do.
and I'm not sure if this is helpful since the process happens in the script but this is my mapped fields.
I have also rechecked the sys_attachment table and I confirmed the images are in there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 10:47 PM
Hi,
update as this
var sa = new GlideSysAttachment();
var attachmentSysId = sa.write(target, fileName, fileContentType, fileData);
var sysId = new global.VariableUtil().copyAttachment(sysId, "ZZ_YY" + target.sys_class_name, target.sys_id);
target.image = attachmentSysId; // give your field name which holds image
target.update();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 11:15 PM