Nom noms

Bassam Itani
Tera Contributor
1 ACCEPTED SOLUTION

Filipe Cruz
Kilo Sage
Kilo Sage

Hi Bassam,

You have two possibilities:

1) update the ui action to resolve the incident, putting there the code to validate if all checklist items are compete or not. If not, abort the Resolution action;
2) on the onSubmit, validate if the state is being changed and only in that situation you will validate the checklist items:

function onSubmit() {

    if (g_form.getValue("state") == 7) { //Closed


        // Check to make sure checklist is complete before continuing
        var ci = new GlideRecord('checklist_item');
        ci.addQuery('checklist.document', g_form.getUniqueValue());
        ci.addQuery('complete', false);
        ci.query(); // Must be a synchronous call because this is an 'onSubmit' script
        if (ci.next()) {
            alert('All checklist items must be completed before this ticket is resolved.');
            return false;
        }
    }
}

(update the value of state to the one you need).

In the end, you are only interested in checking the checklist when resolving/closing the record, so only on that moment you should validate the checklist.

Hope my answer helps you!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

View solution in original post

2 REPLIES 2

Filipe Cruz
Kilo Sage
Kilo Sage

Hi Bassam,

You have two possibilities:

1) update the ui action to resolve the incident, putting there the code to validate if all checklist items are compete or not. If not, abort the Resolution action;
2) on the onSubmit, validate if the state is being changed and only in that situation you will validate the checklist items:

function onSubmit() {

    if (g_form.getValue("state") == 7) { //Closed


        // Check to make sure checklist is complete before continuing
        var ci = new GlideRecord('checklist_item');
        ci.addQuery('checklist.document', g_form.getUniqueValue());
        ci.addQuery('complete', false);
        ci.query(); // Must be a synchronous call because this is an 'onSubmit' script
        if (ci.next()) {
            alert('All checklist items must be completed before this ticket is resolved.');
            return false;
        }
    }
}

(update the value of state to the one you need).

In the end, you are only interested in checking the checklist when resolving/closing the record, so only on that moment you should validate the checklist.

Hope my answer helps you!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

Ravi sah
Tera Contributor

Hey Guys i have found a workaround,

PFB the code and the configurations of the Business rule:

 

Configure a Business rule on HR task(sn_hr_core_task) table and run it before update and under filter condition set state as changes to close complete and HR task type is checklist.

 

Script:

 

(function executeRule(current, previous /*null when async*/) {
 
 
var check_List= new GlideRecord('checklist');
if(check_List.get('document',current.sys_id)){
var checklist_itemGr = new GlideRecord('checklist_item');
checklist_itemGr.addEncodedQuery('complete=false^checklist='+check_List.sys_id); //get the chceklist item of the current checklist item.
checklist_itemGr.query(); 
if(checklist_itemGr.hasNext()) {
 
 
current.setAbortAction(true); // do not let the user submit the task if he has not checked all the checklist items.
}
gs.addErrorMessage('All checklist items must be completed before submission.'); //display the infor message if all checklist items are not checked.
}
 
})(current, previous);