Multi-select new list action in change request list

NMMZ10
Tera Contributor

Implement a multi-select List Action on the Change Request list to allow users to mass-cancel Change Requests that were automatically created from Standard Change templates.

It must be available only for change manager role.

The action must:

Allow selecting multiple Change Requests.

Prompt the user for a comment (mandatory).

Set the state to Cancelled and record the comment in the Work Notes or Closure Notes.

Be reusable for future similar needs.

This prevents abandoned Change Requests when the wrong Standard Change is opened.



The requirements are: 

When triggered:

  • User sees a prompt asking for a mandatory comment.
  • Selected Change Requests change to state Cancelled.
  • The comment is written into work notes or closure notes.

Only visible to appropriate roles (change managers / fulfiller roles).

No impact on existing Standard Change workflows.

What would be the ideal way to create this? How would you do it? 
Ui Action? Ui builder? 

5 REPLIES 5

adityahubli
Giga Guru

Hello @NMMZ10 ,

 Ui Action is best option for this . Please refer this code snippet of script include and client script through which we can acheived this scenario.

Client  Script :

function changeState() {

    var selectedSysIds = g_list.getChecked();
    if(selectedSysIds)
    {
        alert(selectedSysIds);
    }

    if (!selectedSysIds) {
        alert("Please select at least one record.");
        return;
    }

    var comment = prompt("Enter mandatory comment to cancel");

    if (!comment) {
        alert("Comment is mandatory to cancel the request.");
        return;
    }

    var ga = new GlideAjax('cancelChangeState');
    ga.addParam('sysparm_name', 'changeState');
    ga.addParam('sysparm_sys_ids', selectedSysIds);
    ga.addParam('sysparm_comment', comment);

    ga.getXMLAnswer(function (answer) {

        if (answer === 'true') {
            alert('Updated successfully');
            g_list.refresh();
        } else {
            alert('Update failed');
        }
    });
}
 
Script include :
var cancelChangeState = Class.create();
cancelChangeState.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    changeState: function () {

        var sysIds = this.getParameter('sysparm_sys_ids');
        var comment = this.getParameter('sysparm_comment');

        if (!sysIds || !comment) {
            return 'false';
        }

        var gr = new GlideRecord('change_request');
        gr.addEncodedQuery('sys_idIN' + sysIds);
        gr.query();

        while (gr.next()) {
            gr.work_notes = comment;
            gr.state = 4;
            gr.close_code='succesfull_issue';
            gr.close_code='comment';
            gr.update();
        }

        return 'true';
    },

    type: 'cancelChangeState'
});
 
 
adityahubli_0-1767615726676.png            adityahubli_1-1767615756907.png          adityahubli_2-1767615795497.png

 

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya,

Technical consultant