Downloading attachments in workspace

Mahesh_Krishnan
Giga Guru

Hello All:

I have a UI action in both Classic UI and Workspace that allows an agent to download a document from the sys_attachment table. The doc is not directly attached to the case but to another record that is related to the case.

For the classic UI I am using the g_navigation.openRecord method and all is working fine. It appears that this method is not supported in the Workspace client script as I get an error when I turn on Inspect in Chrome. How can I implement what I need in workspace. Below is the code for both the classic and workspace scripts.

 

//classic ui script
var my_ga = new GlideAjax('x_cpts_onboarding.CPTSApplicationDocs');
    my_ga.addParam('sysparm_name', 'getRebateAttachment');
    my_ga.addParam('sysparm_rebatesValue', g_form.getValue('rebates'));
    my_ga.getXML(ValidateData);
}

function ValidateData(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer != '') {
        g_navigation.openRecord('sys_attachment', answer);
    }

 

Workspace Client Script

function onClick(g_form) {
    var my_ga = new GlideAjax('x_cpts_onboarding.CPTSApplicationDocs');
    my_ga.addParam('sysparm_name', 'getRebateAttachment');
    my_ga.addParam('sysparm_rebatesValue', g_form.getValue('rebates'));
    my_ga.getXMLAnswer(function(response) {
        if (response) {	
            g_navigation.openRecord('sys_attachment', response);
        }
    });
}

 

Thanks in advance for your time!

 

Mahesh

1 ACCEPTED SOLUTION

Not sure if there is a better solution, but the below code worked for me in workspace. 

top.window.open("/sys_attachment.do?sys_id=" + response, '_blank');

 I wasn't able to download an attachment via UI action with the OOB workspace APIs. 

View solution in original post

4 REPLIES 4

Elijah Aromola
Mega Sage

For workspace you can try using g_aw.openRecord(); 

g_aw.openRecord('sys_attachment', response); 

 

https://docs.servicenow.com/en-US/bundle/utah-api-reference/page/app-store/dev_portal/API_reference/...

 

Mahesh_Krishnan
Giga Guru

I tried that api as well Elijah. It opens another tab and shows that record but is not downloading it.

Not sure if there is a better solution, but the below code worked for me in workspace. 

top.window.open("/sys_attachment.do?sys_id=" + response, '_blank');

 I wasn't able to download an attachment via UI action with the OOB workspace APIs. 

Mahesh_Krishnan
Giga Guru

Thanks a bunch @Elijah Aromola !!