
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
12-17-2019 08:40 AM - edited 08-17-2024 10:10 PM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
There is a newer version available for this content: "Virtual Agent User Input File Picker [Paris]" |
Hi there,
While browsing Community questions, I noticed some topics about how to apply the User Input 'Image Picker' within the Virtual Agent Designer. Specifically, how to add an image to a (new) record. Not having applied this one myself yet I thought, let's give it a go! Unfortunately, this is the only User Input not being used in the out-of-the-box Topics. Also, the Docs don't mention the full path for using this User Input… as with most in ServiceNow, once having this up-and-running, it actually looks like fairly easy 😀.
Just sharing knowledge gained on how to apply the User Input 'Image Picker'.
Behavior User Input 'Image Picker'
When simply applying the User Input 'Image Picker', you don't really see anything happening after selecting an image. Though, because we know images attached to records are actually stored as attachments, I just had a look at the Attachments [sys_attachment] table.
Filtering on the most recent attachments, notice that a Content type 'image/png' record has been created on the Table name 'sys_cs_conversation_task' and the File name exactly is the file which you just selected with the User Input 'Image Picker'!
Relating the Image to a (new) record
So the User Input 'Image Picker' does work. Though, the image is only added to the Attachments table. So what actually does the vaInput give us? Might that be useful? When applying gs.info(vaInputs.image.toString()), this provides us with something like:
https://instance-name.service-now.com/api/now/v1/cs/media/7ve9KNPje94K14077hEC123WhNjto3c8F68wPW3X8T...
Brainstorming for ideas, moving/duplicating the image, searching the Docs for Virtual Agent Script, I stumbled on vaSystem methods.
The vaSystem methods mentions:
vaSystem.attachToRecord(String mediaId, String tableName, String sysId)
This method attaches an image to a record.
String tableName, String sysId, both look logical. mediaId, would that be what we just wrote to the System Log? Indeed it is 😀.
Solution
Out basic test Topic for the User Input 'Image Picker' looks like:
In this case, we are just creating an Incident. Obviously, attaching the image to an existing record would also work. The Utility 'Script Action' contains :
(function execute() {
vaSystem.attachToRecord(vaInputs.image.getValue(), 'incident', vaInputs.create_incident);
})()
vaInputs.image: image being the Variable Name for User Input 'Image Picker'
vaInputs.create_incident: create_incident being the Variable Name for Utility 'Action'
Result
If we open the just created Incident, notice that the Image from the User Input 'Image Picker' indeed has been attached to the Incident:
---
And that's it actually. Hope you like it. If any questions or remarks, let me know!
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group
---
- 4,526 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for continuing to share your knowledge!

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I've been using this for a bit and just tried two different ways to upload and attach multiple files but am having no luck...
The first try was the simplest, though I didn't expect much; I simply looped through the same single Image Picker to upload multiple files and then at the end just attached this image picker to the record but actually nothing got attached, not the original upload nor the replacement upload. Didn't expect it to work but it was simple enough to try.
The second try I expected to work but am now confused since it's not working; I simply hard-coded three Image Pickers that are only visible, respectively, if the user chooses 1-3 attachments. Going through the conversation log, I can confirm that the different files are uploaded properly and separately, but later in the conversation when I actually go to attach them - I also logged their values for debugging - only the first one gets attached and the other ones are null.
This second method would have already been inconvenient and a bad development practice, but at least it can be relatively easily done, especially with a Topic Block in Orlando. But the fact that even this isn't working is bewildering. The Image Picker just seems oddly weak and undeveloped...
Add Attachment Script Action (unpictured, after the INC is created):
(function execute() {
gs.log('FILE 1: '+vaInputs.file_upload_1.getValue());
gs.log('FILE 2: '+vaInputs.file_upload_2.getValue()); //always returns null
gs.log('FILE 3: '+vaInputs.file_upload_3.getValue()); //always returns null
if (vaInputs.file_upload_1.getValue() != null){
vaSystem.attachToRecord(vaInputs.file_upload_1.getValue(), 'incident',vaInputs.create_incident);
if (vaInputs.file_upload_2.getValue() != null){
vaSystem.attachToRecord(vaInputs.file_upload_2.getValue(), 'incident',vaInputs.create_incident);
if (vaInputs.file_upload_3.getValue() != null){
vaSystem.attachToRecord(vaInputs.file_upload_3.getValue(), 'incident',vaInputs.create_incident);
}
}
}
})()

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Update: I figured out how to do multiple attachments on a record...
I went back to Method 1, looping through a single Image Picker. The difference to get it to work is that it needs to happen after the record is created. This allows the user to attach as many files as they want to the record.
This is a much better practice than hardcoding multiple Image Pickers and most importantly, it works!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Excellent documentation, this helps
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
The article helped me. Thanks for sharing your knowledge!!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Awesome article, @Mark Roethof! Straight to the point and helpful!