How to add multiple attachments from Virtual Agent while creating the Incident?

Vijaya13
Tera Contributor

How to add multiple attachments from Virtual Agent while creating the Incident. 

7 REPLIES 7

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

For context, here are the input variables:

ChrisD_0-1730941067812.png

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);
    }
})()

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);
    }
})()