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

Thank you Supriya,

 

This script worked perfectly as intended!

Eric Manning
Tera Contributor

Does this solution work for others folks as well? I get :

Uncaught ReferenceError: KBKnowledge is not defined at moveToRetire

ronhrhr
Tera Contributor

Its working, but some of the article are  going in "Pending Reirement" state instead of "Retired"

 

Do you have an approval process for retiring articles? Check the related approval records to see if one was created when trying to retire.