- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 10:34 AM
Hello,
I am trying to pass the sys_id of an attachment from the server side code into the client and having issues. What am I doing wrong with this code? Please help.
Server Side
// need make the attachment download dynamic
var kbArticle = {};
data.kbArticle = '';
var findAttachment = new GlideRecord("sys_attachment");
findAttachment.addEncodedQuery("table_sys_idSTARTSWITH" + kbSysID + "^ORtable_sys_idSTARTSWITH" + kbSysID2);
findAttachment.query();
if (findAttachment.next() && action){
data.kbArticle = kbArticle;
if (action == "NDA"){
data.kbArticle.sys_id = findAttachment.sys_id.toString();
}
}
Client Code
function($location, $window) {
/* widget controller */
var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
// do something window location
if (c.data.action == 'NDA') {
var url = 'sys_attachment.do?sys_id=' + c.kbArticle.sys_id;
$window.open(url);
}
});
};
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 10:43 AM
Hi @Jalen Dixon
In the client-side code, you're attempting to access c.kbArticle.sys_id, but kbArticle is not directly accessible within the client script because it's stored in c.data.kbArticle. You need to access it as c.data.kbArticle.sys_id. Here's the corrected client-side code:
function($location, $window) {
/* widget controller */
var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
// do something window location
if (c.data.action == 'NDA') {
var url = 'sys_attachment.do?sys_id=' + c.data.kbArticle.sys_id; // Access kbArticle as c.data.kbArticle.sys_id
$window.open(url);
}
});
};
}
HIT Helpful & Accept the solution!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 10:43 AM
Hi @Jalen Dixon
In the client-side code, you're attempting to access c.kbArticle.sys_id, but kbArticle is not directly accessible within the client script because it's stored in c.data.kbArticle. You need to access it as c.data.kbArticle.sys_id. Here's the corrected client-side code:
function($location, $window) {
/* widget controller */
var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
// do something window location
if (c.data.action == 'NDA') {
var url = 'sys_attachment.do?sys_id=' + c.data.kbArticle.sys_id; // Access kbArticle as c.data.kbArticle.sys_id
$window.open(url);
}
});
};
}
HIT Helpful & Accept the solution!!