Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

After the state changes to Closed Complete, all corrective actions need to be verified.

may13
Tera Contributor
In ServiceNow HRSD, under Employee Relations, if my HR case is marked as Closed Complete, I need to verify all corrective actions. If any corrective action is not in Complete status, the HR case cannot be closed, and we should display an error message. If all corrective actions are in Complete status, then I can close the HR case. After closing, all fields in the corrective actions should become read-only.
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@may13 

what do you mean by corrective action? HR case has HR tasks associated to it

you can use before update business rule and validate if any HR task is open when HR case is about to close, if yes then abort the update

HR case should not closed if any HR task is open 

AnkurBawiskar_0-1765085215017.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@may13 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

ThePatel
Mega Contributor

You can write a business rule or do a check in your flow by doing a query to the corrective action table. You can pass the hr case sys_id if corrective actions are not in a closed state you can abort action on the hr case and show an error message. 


Example BR on HR Case table

When: Before Update
Conditions: State changes to Closed Complete

    // Check if the case is being closed
    if (current.state == 'closed_complete' && previous.state != 'closed_complete') { 
        
        // Query all corrective actions related to this HR case
        var correctiveAction = new GlideRecord('XXXXXX'); // Table name replace the XXXXX
        correctiveAction.addQuery('hr_case', current.sys_id); // Adjust field name if different
        correctiveAction.query();
        
        var incompleteActions = [];
        
        while (correctiveAction.next()) {
            // Check if any corrective action is not in Complete status
            if (correctiveAction.state != 'complete') { // Adjust state value if different
                incompleteActions.push(correctiveAction.number.toString());
            }
        }
        
        // If there are incomplete corrective actions, prevent closure
        if (incompleteActions.length > 0) {
            gs.addErrorMessage('Cannot close HR Case. The following corrective action(s) are not complete: ' + incompleteActions.join(', '));
            current.setAbortAction(true);
        }
    }