The CreatorCon Call for Content is officially open! Get started here.

UI Action with confirmation

Eric Manning
Tera Contributor

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.

find_real_file.png

 

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

find_real_file.png

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage
Mega Sage

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.

find_real_file.png

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

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

1 REPLY 1

Ahmmed Ali
Mega Sage
Mega Sage

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.

find_real_file.png

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

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali