- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2018 12:24 PM
There are many articles that describe how to do this but nothing I try works. I copied the existing KB Retire UI Action and made changes based on many other articles.
In the script below if I include the if (typeof window == 'undefined') then the retireArticle() doesn't fire. If I remove this statement I get Uncaught "ReferenceError: KBKnowledge is not defined" and the function doesn't fire. Any help is greatly appreciated.
Here is the script:
function retire(){
var answer=confirm("To confirm that you want to permanently retire this article please select OK otherwise Cancel");
if (!answer) {
alert('This article was not retired');
} else {
gsftSubmit(null, g_form.getFormElement(), 'retire'); // copy UI action name
}
}
if(typeof window == 'undefined')
retireArticle();
function retireArticle(){
if(new KBKnowledge().canRetire(current)){
if (current.kb_knowledge_base.kb_version == "3" && new KBWorkflow().startWorkflow(current, "retire_workflow")) {
if(current.workflow_state != 'retired'){
current.update();
}
gs.addInfoMessage(new KBKnowledge().getStateMessage(current.getValue("workflow_state")));
} else if (current.kb_knowledge_base.kb_version == "2") {
current.workflow_state = 'retired';
current.update();
gs.addInfoMessage(new KBKnowledge().getStateMessage(current.getValue("workflow_state")));
}
if(typeof RP !== 'undefined'){
if(RP.getParameterValue("sysparm_referring_url").indexOf('kb_view.do') >= 0){
gs.setRedirect("kb_view.do?sys_kb_id=" + current.sys_id);
}
}
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2018 02:15 PM
Hello Eric,
try changing action name to something unique. (as retire is already used in OOTB ui action).
I tried below and worked for me.
function retire(){
var answer=confirm("To confirm that you want to permanently retire this article please select OK otherwise Cancel");
if (!answer) {
alert('This article was not retired');
return false;
} else {
gsftSubmit(null, g_form.getFormElement(), 'retireTest'); // Just give here new action name
}
}
if(typeof window == 'undefined')
retireArticle();
function retireArticle(){
if(new KBKnowledge().canRetire(current)){
if (current.kb_knowledge_base.kb_version == "3" && new KBWorkflow().startWorkflow(current, "retire_workflow")) {
if(current.workflow_state != 'retired'){
current.update();
}
gs.addInfoMessage(new KBKnowledge().getStateMessage(current.getValue("workflow_state")));
} else if (current.kb_knowledge_base.kb_version == "2") {
current.workflow_state = 'retired';
current.update();
gs.addInfoMessage(new KBKnowledge().getStateMessage(current.getValue("workflow_state")));
}
if(typeof RP !== 'undefined'){
if(RP.getParameterValue("sysparm_referring_url").indexOf('kb_view.do') >= 0){
gs.setRedirect("kb_view.do?sys_kb_id=" + current.sys_id);
}
}
}
}
Thanks,
Ali
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2018 02:15 PM
Hello Eric,
try changing action name to something unique. (as retire is already used in OOTB ui action).
I tried below and worked for me.
function retire(){
var answer=confirm("To confirm that you want to permanently retire this article please select OK otherwise Cancel");
if (!answer) {
alert('This article was not retired');
return false;
} else {
gsftSubmit(null, g_form.getFormElement(), 'retireTest'); // Just give here new action name
}
}
if(typeof window == 'undefined')
retireArticle();
function retireArticle(){
if(new KBKnowledge().canRetire(current)){
if (current.kb_knowledge_base.kb_version == "3" && new KBWorkflow().startWorkflow(current, "retire_workflow")) {
if(current.workflow_state != 'retired'){
current.update();
}
gs.addInfoMessage(new KBKnowledge().getStateMessage(current.getValue("workflow_state")));
} else if (current.kb_knowledge_base.kb_version == "2") {
current.workflow_state = 'retired';
current.update();
gs.addInfoMessage(new KBKnowledge().getStateMessage(current.getValue("workflow_state")));
}
if(typeof RP !== 'undefined'){
if(RP.getParameterValue("sysparm_referring_url").indexOf('kb_view.do') >= 0){
gs.setRedirect("kb_view.do?sys_kb_id=" + current.sys_id);
}
}
}
}
Thanks,
Ali
Thank you,
Ali