- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 01:46 PM
Hey Community,
I'm working on making a client script that forces a confirmation dialog box when a user tries to click the retire button in an article. The box pops up properly when selected, but when you click "OK" it re-routes directly back to the dialog box. It will only successfully retire the article after you hit "OK" once then click "Cancel" the second time. Below is the code I'm using in the client script. Any suggestions would be greatly appreciated!
function onSubmit() {
var action = g_form.getActionName();
if(action=="retire"){ //Retire button's action name
var answer = confirm('Are you sure you want to retire this article?');
if(answer == true){
gsftSubmit(null, g_form.getFormElement(), 'retire'); //Retire button's action name
}
else{
return false;
}
}
}
Solved! Go to Solution.
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 03:17 PM
Hi Chazzer,
The below code works for me.
moveToRetire() ;
function retire(){ var answer=confirm("ARe you sure you want to retire this article");
if (!answer)
{
alert('This article was not retired');
}
else{
gsftSubmit(null, g_form.getFormElement(), 'retire'); // copy UI action name
}
}
function moveToRetire(){
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);
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 02:30 PM
I don't think you need to re-call the button click in the 'gsftSubmit' line because it's already been clicked, right? How about this? The difference is that it simply returns the answer (true or false) that comes back from the click in the confirmation box. If they click 'OK', it will return true and continue with the submit, otherwise it will stop.
function onSubmit() {
var action = g_form.getActionName();
if(action=="retire"){ //Retire button's action name
return confirm('Are you sure you want to retire this article?');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2018 06:58 AM
Thanks Mark,
I tried this script, but found using the OnClick client callable script in the UI Action was a better fit for this situation. Using a normal client script, I could get the article to retire, but it wouldn't go through proper retire workflow set behind the articles.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2018 07:05 AM
Did this script resolve the problem you described in your original post?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 03:17 PM
Hi Chazzer,
The below code works for me.
moveToRetire() ;
function retire(){ var answer=confirm("ARe you sure you want to retire this article");
if (!answer)
{
alert('This article was not retired');
}
else{
gsftSubmit(null, g_form.getFormElement(), 'retire'); // copy UI action name
}
}
function moveToRetire(){
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);
}
}
}
}