Get sys_id of attachment in ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2024 01:45 AM
Hi, I have a button on workbench.. I want to download the attachment of the record. it is not working. Button is on workspce.
function onClick(g_form) {
var sysID = g_form.getUniqueValue();
var gr = new GlideRecord("sys_attachment");
gr.addQuery('table_sys_id', sysID);
gr.query();
while (gr.next()) {
var attSysID = gr.sys_id;
}
alert(sysID);
var URL = '/sys_attachment.do?sys_id='+attSysID;
//window.open(URL, '_blank');
//action.setRedirectURL(URL);
//action.setReturnURL(current);
top.window.open(URL, 'blank');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2024 01:45 AM
Sys id is showing as undefined

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2024 01:52 AM
Hi @Rosy14 can you try the below code and share the result of alert
function onClick(g_form) {
var attSysID;
var sysID = g_form.getUniqueValue();
alert("record sysid is "+sysID);
var gr = new GlideRecord("sys_attachment");
gr.addQuery('table_sys_id', sysID);
gr.query();
while (gr.next()) {
attSysID = gr.getValue('sys_id');
}
alert("attachment record sysid is "+attSysID);
var URL = '/sys_attachment.do?sys_id='+attSysID;
//window.open(URL, '_blank');
//action.setRedirectURL(URL);
//action.setReturnURL(current);
//top.window.open(URL, 'blank');
g_navigation.open(URL, '_blank');
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2024 02:00 AM
1st alert showing correct but 2nd one is undefined.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2024 02:17 AM
Hi @Rosy14 I see the issue here, tested now works fine, You need to use script include and ajax in UI action as below
Script Include function below
Harish