Need a prompt box for comments when Cancelling a Requested Item ticket in UI Action

EricG
Kilo Sage

I have a UI Action that will cancel the RITM ticket once click.

The code i have is working ok.   The Child Tickets are closed incomplete as is everything else.

//closing any child records
var currChld = new GlideRecord('sc_task');
currChld.addQuery('request_item',current.sys_id);
currChld.addQuery('active',true);
currChld.query();

while(currChld.next()){
	currChld.state = 9;
	currChld.active = false;
	currChld.close_notes = "Ticket was cancelled by "+gs.getUserDisplayName();
	currChld.update();
}

//Closing parent REQ
var currReq = current.request;
gs.info('The current req is '+currReq+' and the number is '+currReq.number);
var cancelTicket = new GlideRecord('sc_request');
cancelTicket.addQuery('sys_id',currReq);
cancelTicket.query();

while(cancelTicket.next()){
	cancelTicket.request_state = 'closed_cancelled';
	cancelTicket.stage = 'closed_incomplete';
	cancelTicket.update();
}

current.close_notes = "This request was cancelled by "+gs.getUserDisplayName();
current.update();

 

The UI Action is a Form Button and shows on Update.

EricG_0-1699650798692.png

 

What I'd like to do is Prompt the user for a reason for cancelling, so that the close notes are more complete.

 

Any thoughts?

1 REPLY 1

Clara Lemos
Mega Sage
Mega Sage

Hi @EricG ,

 

What if we add a popup that prompts, asking to confirm whether the cancel reason is in the close notes? If they answer positively, your code will run, and if they answer negatively, no modification will be done.

 

If that sounds good, all you need to do is: 

First  set client as true and the Onclick: the name of your UI action 

Screenshot 2023-11-11 at 08.26.53.png

 Then make the following modification on your script:

 

 

function onCancel() {
    var answer = confirm('Did you add the cancel reason into the Close Notes?');
    if (answer) {
        gsftSubmit(null, g_form.getFormElement(), 'cancel_ritm'); //cancel_ritm is the UI action name that we set in the first step
    } else {
        return;
    }
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    updateTask();

function updateTask() {
    //closing any child records
    var currChld = new GlideRecord('sc_task');
    currChld.addQuery('request_item', current.sys_id);
    currChld.addQuery('active', true);
    currChld.query();

    while (currChld.next()) {
        currChld.state = 9;
        currChld.active = false;
        currChld.close_notes = "Ticket was cancelled by " + gs.getUserDisplayName();
        currChld.update();
    }

    //Closing parent REQ
    var currReq = current.request;
    gs.info('The current req is ' + currReq + ' and the number is ' + currReq.number);
    var cancelTicket = new GlideRecord('sc_request');
    cancelTicket.addQuery('sys_id', currReq);
    cancelTicket.query();

    while (cancelTicket.next()) {
        cancelTicket.request_state = 'closed_cancelled';
        cancelTicket.stage = 'closed_incomplete';
        cancelTicket.update();
    }

    current.close_notes = "This request was cancelled by " + gs.getUserDisplayName();
    current.update();
}

If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know

Cheers