Revert to New from scheduled state in change request is not working

Revathi12
Tera Contributor

When we click on Revert to New button when the change is in scheduled state its not moving to new state. Below is the script which we are trying. Can you please help

 

UI Action :

function revertNew() {
    var dialog = new GlideDialogWindow("Confirm_revert");
    dialog.setTitle('Confirmation');
    dialog.render();
}

if (typeof window == 'undefined') {
    revertToNew(current);
}

function revertToNew(changeRequestGr) {
    var z = (current.type == ChangeRequest.EMERGENCY) && (new ChangeRequest(current).isAuthorize() || new ChangeRequest(current).isAssess() || new ChangeRequest(current).isScheduled() || new ChangeRequest(current).isNew());
    if (z) {
        current.approval = 'not requested';
        current.update();
    } else if (current.type == ChangeRequest.NORMAL && (new ChangeRequest(current).isAuthorize() || new ChangeRequest(current).isScheduled() || new ChangeRequest(current).isAssess())) {
        current.setValue('on_hold', false);
        current.approval = 'not requested';
        current.update();

        var x = new GlideRecord('sysapproval_approver');
        x.addQuery('sysapproval=' + current.sys_id + '^state=requested');
        x.query();
        while (x.next()) {
            x.setValue('state', 'cancelled');
            x.update();
        }
       

    } else if ((current.type == 'expedited') && (current.state == '-2' || current.state == '-3' || current.state == '-4' || current.state == '-5')) {
        var y = new GlideRecord('sysapproval_approver');
        y.addQuery('sysapproval=' + current.sys_id);
        y.query();
        while (y.next()) {
            y.setValue('state', 'cancelled');
            y.update();
        }
       

    var changeRequest = new ChangeRequest(changeRequestGr);
    if (!changeRequest.revertToNew())
        gs.addErrorMessage(gs.getMessage('State Model for {0} changes does not allow reverting change from {1} state', [changeRequest.getValue('type'), changeRequest.getDisplayValue('state')]));
    action.setRedirectURL(current);

}

 

 

Script Include :

 

var ChangeMgmtUtils = Class.create();
ChangeMgmtUtils.prototype = {
    initialize: function() {

    },
    //This function is to check with the RevertToNew UiAction
    CheckAccessforRevertToNew: function(current) {
        if (gs.hasRole('change_manager')) {
            if (current.type == ChangeRequest.EMERGENCY && new ChangeRequest(current).isAuthorize()|| new ChangeRequest(current).isAssess()||  new ChangeRequest(current).isScheduled()) {
                return true;
            } else if ((current.type == ChangeRequest.NORMAL && new ChangeRequest(current).isAssess())||( new ChangeRequest(current).isAuthorize()) ||( new ChangeRequest(current).isScheduled() )) {
                return true;
               
            }else if (current.type == ChangeRequest.STANDARD && new ChangeRequest(current).isScheduled()) {
                return true;
               
            }
        else {
                return false;
            }
        } else {
            return false;
        }
    },
    type: 'ChangeMgmtUtils'
};
 
 
1 REPLY 1

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Revathi12 

 

Please check OOTB UI action Revert to New and make the changes accordingly.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************