Change Management - Any state to cancelled except Closed

JulietD
Mega Guru

Hi,

 

As a member of the assigned change management group of the service offering, I want to be able to cancel the Change at any stage (not closed), so that if it was raised in error, the process can continue.

 

I created a new UI action with condition and filter as below,

 

condition:

current.state != 'closed' && gs.hasRole('change_manager')

 

Script:

(function executeCancelChange() {
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group', current.assignment_group);
    gr.addQuery('user', gs.getUserID());
    gr.query();
   
    if (gr.next()) {
        current.state = 'cancelled'; // Replace 'cancelled' with the actual state value if different
        current.update();
        gs.addInfoMessage('The change request has been cancelled.');
    } else {
        gs.addErrorMessage('You are not a member of the assigned change management group.');
    }
})();
 
But this is not working for me. Can anyone help?
1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi juliet,

 

You can check if the user is part of the assignment group also in the ui action condition. Also you need to use the value of the state fields , here are the cancelled and closed values

AnuragTripathi_0-1716884407162.png

 

 

So your condition becomes

current.state != '3' && gs.hasRole('change_manager') && gs.getUser().isMemberOf(''+current.assignment_group); 

Make sure this is a server side ui action

Script of the ui action

   current.state = '4'; // Replace 'cancelled' with the actual state value if different
        gs.addInfoMessage('The change request has been cancelled.');
current.update();

 

 

 

 

-Anurag

View solution in original post

3 REPLIES 3

Deepak Shaerma
Kilo Sage

Hi @JulietD 

Your ui action script is almost seems to correct, but assignment_group on a change request might be different than the group responsible for change management. Hoope this is the point where script fails in result.
1. Condition:


current.state != 'closed' && gs.hasRole('change_manager')

Script:

 

(function executeCancelChange() {
        var userInGroup = new GlideRecord('sys_user_grmember');
        userInGroup.addQuery('group', current.assignment_group.toString()); // Convert assignment_group to string if necessary
        userInGroup.addQuery('user', gs.getUserID());
        userInGroup.query();
        
        if (userInGroup.next()) {
            current.setValue('state', 'Cancelled'); // Ensure ‘Cancelled’ is the correct state value in your instance
            current.update();
            gs.addInfoMessage('The change request has been cancelled.');
        } else {
            gs.addErrorMessage('You are not a member of the assigned change management group.');
        }
    })();

 


Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards
Deepak Sharma 

Anurag Tripathi
Mega Patron
Mega Patron

Hi juliet,

 

You can check if the user is part of the assignment group also in the ui action condition. Also you need to use the value of the state fields , here are the cancelled and closed values

AnuragTripathi_0-1716884407162.png

 

 

So your condition becomes

current.state != '3' && gs.hasRole('change_manager') && gs.getUser().isMemberOf(''+current.assignment_group); 

Make sure this is a server side ui action

Script of the ui action

   current.state = '4'; // Replace 'cancelled' with the actual state value if different
        gs.addInfoMessage('The change request has been cancelled.');
current.update();

 

 

 

 

-Anurag

Thank you so much 😊