Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

knowledge checkbox on incident form

jean-pauldehaas
Tera Guru

Hi,

 

We have the knwoledge checkbox on the incident form under the resolution tab, we have set it up when a user resolves a ticket and checks the box it creates an KB article in draft.

The knowledge base it creates it in is some kind of default knowledge base which is set by a BR script, we want to prompt the user to select the correct knowledge base.

 

any ideas ?

14 REPLIES 14

Community Alums
Not applicable

Hi @jean-pauldehaas ,

 

1. Deactivate the OOTB BR to create Knowledge when Checkbox is true and incident changes to Closed.

2. Create onSubmit client script with below script:

function onSubmit() {
    if (g_scratchpad._action_confirmed) {
        return true;
    }

    var state = g_form.getValue('state');
    var knowledge = g_form.getValue('knowledge');
    var shortDes = g_form.getValue('short_description');
    var num = g_form.getValue('number');
    if (state == '7' && knowledge) {
        var gm = new GlideModal("glide_prompt", true, 600);
        gm.setTitle("Confirm Knowledge Base");
        gm.setPreference("title", "Please enter the knowledge base");
        gm.setPreference("onPromptComplete", doComplete);
        gm.setPreference("onPromptCancel", doCancel);
        gm.render();
    }

    function doComplete(value) {
        if (value != '') {
            var ga = new GlideAjax('validateHelper');
            ga.addParam("sysparm_name", 'createArticle');
            ga.addParam("sysparm_input", value.toString());
            ga.addParam("sysparm_sysID", g_form.getUniqueValue());
            ga.addParam("sysparm_shortDes", shortDes);
            ga.addParam("sysparm_num", num);
            ga.getXMLAnswer(getResponse);
        } else alert('You should enter the knowledge base');
    }

    function getResponse(response) {
        if (response != 'Knowledge base not found') {
            g_scratchpad._action_confirmed = true;
            gsftSubmit(null, g_form.getFormElement(), g_form.getActionName());
			g_form.addInfoMessage(response);
        } else alert(response);
    }

    function doCancel(value) {
        alert("in doCancel.  Update is aborted.  value = " + value);
    }
    return false;


}

3. Create a Script Include "validateHelper", Client callable is True, with Script as below:

createArticle: function() {
        var result;
        var input = this.getParameter('sysparm_input');
        var sysID = this.getParameter('sysparm_sysID');
        var shortDes = this.getParameter('sysparm_shortDes');
		var num = this.getParameter('sysparm_num');
        var base = new GlideRecord("kb_knowledge_base");
        base.addQuery('title', input);
        base.query();
        if (base.next()) {
            var kb = new GlideRecord("kb_knowledge");
            kb.source = sysID;
            kb.short_description = shortDes;
            kb.sys_domain = 'global';
            kb.workflow_state = 'draft';
            kb.kb_knowledge_base = base.getUniqueValue();
            kbSysId = kb.insert();
            if (kbSysId) {
				result = gs.getMessage('Knowledge Article created: {0} based on closure of Incident: {1}', [kb.number, num])
            }
        } else result = 'Knowledge base not found';
        return result;
    },

 

Please test it and give your feedback.

@Community Alums thanks i tried it but nothing pops up where i can enter the knowledge base when i resolve an incident.

any idea?

Community Alums
Not applicable

@jean-pauldehaas you mean there was no pop-up modal? I tried multiple times it worked.

Could you check if this condition is correct? Which of the below alerts appear?

alert(state + ' ' + knowledge)
if (state == '7' && knowledge) {
   alert('condition true')
}

 Note that you have to change the Incident state from other states to Closed and Knowledge checkbox is ticked -> Save the record -> Modal displays

@Community Alums this is how the client script looks like :

jeanpauldehaas_0-1712823510423.png

 

The 2 alert lines were not in your previous script

 

also it needs to appear on resolve not closed but thats why i changed 7 to 6

 

Community Alums
Not applicable

@jean-pauldehaas The client script should run on Incident table, this is where we handle the pop-up