How to add multiple attachments from Virtual Agent while creating the Incident?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 05:16 AM
How to add multiple attachments from Virtual Agent while creating the Incident.
- Labels:
-
Agent Chat
-
AI Search
-
Virtual Agent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 09:05 AM
Hi Chris,
Can you please share the script for attach file to record (canwrite is true) and few lines of explanation which would help me to understand better.
thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 05:00 PM
For context, here are the input variables:
And here is the very advanced script to check if a user has write access 🙂
(function execute() {
var gr = new GlideRecord(vaInputs.table_name);
gr.get(vaInputs.record_sys_id);
vaVars.canWrite = gr.canWrite();
})()
And here's the "Attach file(s) (canWrite = false)" script:
(function execute() {
//if the users doesn't have write access to the record, this is the workaround to attach the file(s)
if (vaVars.attachment_count > 0 && !vaVars.canWrite) {
var currentConversation = vaSystem.getConversationId();
//get the current Conversation Task which is where the most recent attachment is stored
var currentTask = new GlideRecord('sys_cs_conversation_task');
currentTask.addQuery('conversation', currentConversation);
currentTask.orderByDesc('sys_created_on');
currentTask.query();
currentTask.next();
//copies all files uploaded here to the specified record
GlideSysAttachment.copy('sys_cs_conversation_task', currentTask.sys_id, vaInputs.table_name, vaInputs.record_sys_id);
}
})()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 06:15 AM
Oh whoops, I shared canWrite = false...
This is the canWrite = true script:
(function execute() {
vaVars.attachment_count++;
//if the user doesn't have write access to the table, they can't use vaSystem.attachToRecord()
if (vaVars.canWrite){
vaSystem.attachToRecord(vaInputs.file_upload, vaInputs.table_name, vaInputs.record_sys_id);
}
})()