Creating a Confirmation Dialog Upon Article Retire

Chaz
Tera Guru

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;

       }
    }
}

1 ACCEPTED SOLUTION

supriya29
Giga Expert

Hi Chazzer,

The below code works for me.

 

find_real_file.png

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);
		}
	}
}

		  	  
				  }

View solution in original post

8 REPLIES 8

Mark Stanger
Giga Sage

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?');
    }
}

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.

Did this script resolve the problem you described in your original post?

supriya29
Giga Expert

Hi Chazzer,

The below code works for me.

 

find_real_file.png

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);
		}
	}
}

		  	  
				  }