i want to customize OOB cancel change UI action on change form

Abhilasha G T
Tera Contributor

Hi Team,

I have the requirement like below,

 1. When the Cancel UI Action is used, all Active Child Change Tasks should have the following values updated
If the Change Task Type is Implementation
State = Closed
Close Code = Not Attempted
Close Notes = The Implementation was not attempted


If the Change Task Type is Testing
State = Closed
Close Code = Not Attempted
Close Notes = The Change was cancelled


If the Change Task Type is any other Change Task Type:
State = Closed
Close Code = Not Attempted
Close Notes = The Change was cancelled


3. When a Change User uses the Cancel UI Action Button, the Change's Close Notes should be populated with the cancellation comments (cancellation reason field )

how to achieve this.

 

Regards,

Abhilasha G T

6 REPLIES 6

AshishKM
Kilo Patron
Kilo Patron

Hi @Abhilasha G T , 

You can write new UI Action [ Cancel ] on Change [ change_request ] table and apply all logic for Change Task.

 

In script code, first read all active change task via gliderecord query and while itrating the result set ( using while loop ) apply the IF condition to check the Change Task Type for  state,code and notes update.

 

Have you writen any code for this, if yes please share.

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hi Ashish,

Thanks for ur reply ,

Need to customize the OOB ui action only.

Since in this  ui action ,client  check box is enabled can't glide the record

I have created  client callable script  include and called that in UI action.

That is not working. 

Please share the code.


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hi Ashish,

Please check below codes for UI action and Script Include,

AbhilashaGT_0-1746100497612.png

Condition:gs.hasRole('itil,sn_change_write') && new ChangeFormUI(current).isCancelAvailable() &&(current.state!='0' || current.state!='3' || current.state!='4')

AbhilashaGT_1-1746100608335.png

Script Include

AbhilashaGT_2-1746100666203.png

 

var CancelChangeProcessor = Class.create();
CancelChangeProcessor.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    cancelChange: function() {
        var changeId = this.getParameter('sysparm_change_id');
        var reason = this.getParameter('sysparm_reason');

        if (!changeId || !reason) {
            return 'failure';
        }

        var changeGR = new GlideRecord('change_request');
        if (!changeGR.get(changeId)) {
            return 'failure';
        }

        // Close all active Change Tasks
        var taskGR = new GlideRecord('change_task');
        taskGR.addQuery('change_request', changeId);
        taskGR.addQuery('state', '!=', '3'); // Not Closed
        taskGR.query();

        while (taskGR.next()) {
            taskGR.state = 3; // Closed
            taskGR.close_code = 'not_attempted';

            var taskType = taskGR.change_task_type + '';
            if (taskType === 'testing') {
                taskGR.close_notes = 'The CI Implementation was not attempted';
            } else {
                taskGR.close_notes = 'The Change was cancelled';
            }

            taskGR.update();
        }

        // Update Change
        changeGR.state = 4; // Cancelled
        changeGR.close_code = 'cancelled';
        changeGR.close_notes = reason;
        changeGR.update();

        return 'success';
    }
});