Applying a checklist template to an incident by client script?

Cheski Frank
Tera Contributor

Dear community,

I created a Checklist template called "ServiceNow Checklist" and I would like to apply it to the current incident with an onChange client script whenever the category of the incident changes).

Any idea how to do that?

Thanks and kind regards,

Cheski

2 REPLIES 2

Alka_Chaudhary
Mega Sage
Mega Sage

Hello @Cheski Frank ,

 

You can use applyTemplate("sys_id_of_template") in your onChange client script to apply a template.

 

//Example code when category is hardware apply specific template

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    try {
        if (newValue == 'hardware') {// specific condition
            applyTemplate('ba93821883c156105dfdf7c6feaad3f8');// template sys id
            //Clear the template once it is applied
            window.setTimeout(clearTemplate, 2000);
        }
    } catch (e) {
        //alert(e);
    }
}

function clearTemplate() {
    g_form.setValue('u_template', '');
}

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍!

 

Thanks,

Alka

Hi @Alka_Chaudhary ,

That works for incident templates but not for checklists. Apparently that requires some server-sided lookup (script include)? Looking with a developer, thought it would be much easier.

Kind regards,

Cheski