Add Confirm Pop up message in UI Action.

Abhishek Dixit1
Kilo Expert

I want to add Confirm Pop message "Please make sure problem workaround field has been updated before closing incident" 

Button --- CONFIRM or CANCEL

If user select CONFIRM button UI Action will RUN. 

If user select CANCEL button UI action will not RUN and stays in same page. 

Current UI Action script code is as below on problem table.  

var incident = new GlideRecord("incident");
incident.addQuery("problem_id", "=", current.sys_id);
incident.addQuery("incident_state", "=", IncidentState.AWAITING_PROBLEM);
if ( (typeof IncidentReason) !== "undefined" )
incident.addQuery("hold_reason", "=", IncidentReason.AWAITING_PROBLEM);
incident.query();
while (incident.next()) {
incident.incident_state.setValue(IncidentState.RESOLVED);
incident.close_notes = 'This incident is resolved based on workaround provided in related problem investigation number ' + current.number + '.' + ' The Workaround is ' + '(' + current.work_around + ')';
incident.close_code = 'solved_workaround';
incident.update();
gs.addInfoMessage(gs.getMessage('Related Incidents Resolved'));
action.setRedirectURL(current);
}

 

1 ACCEPTED SOLUTION

You are using server side code in the client side.

Try the below script and see if it works

function resolveIncidents() {
    var answer = confirm("Please ensure workaround field has been updated before resolving related incidents.");
    if (answer == true) {
        gsftSubmit(null, g_form.getFormElement(), 'resolveincidents');
} else {
    return false;
}
}

if (typeof window == 'undefined')
    resolveIncidentFunction();

function resolveIncidentFunction() {

    var incident = new GlideRecord("incident");
    incident.addQuery("problem_id", "=", current.sys_id);
    incident.addQuery("incident_state", "=", IncidentState.AWAITING_PROBLEM);
    if ((typeof IncidentReason) !== "undefined")
        incident.addQuery("hold_reason", "=", IncidentReason.AWAITING_PROBLEM);
    incident.query();
    while (incident.next()) {
        incident.incident_state.setValue(IncidentState.RESOLVED);
        incident.close_notes = 'This incident is resolved based on workaround provided in related problem investigation number ' + current.number + '.' + ' The Workaround is ' + '(' + current.work_around + ')';
        incident.close_code = 'solved_workaround';
        incident.update();
        gs.addInfoMessage(gs.getMessage('Related Incidents Resolved'));
        action.setRedirectURL(current);
    }
}

View solution in original post

8 REPLIES 8

Abhishek Dixit1
Kilo Expert

I have tried by updating below script as onclick but UI action does not run if I am selecting OK or CANCEL button. Can anyone help by fixing this code. 

function resolveIncidents(){
var answer=confirm("Please ensure workaround field has been updated before resolving related incidents.");
if (answer==true){
var incident = new GlideRecord("incident");
incident.addQuery("problem_id", "=", current.sys_id);
incident.addQuery("incident_state", "=", IncidentState.AWAITING_PROBLEM);
if ( (typeof IncidentReason) !== "undefined" )
incident.addQuery("hold_reason", "=", IncidentReason.AWAITING_PROBLEM);
incident.query();
while (incident.next()) {
incident.incident_state.setValue(IncidentState.RESOLVED);
incident.close_notes = 'This incident is resolved based on workaround provided in related problem investigation number ' + current.number + '.' + ' The Workaround is ' + '(' + current.work_around + ')';
incident.close_code = 'solved_workaround';
incident.update();
gs.addInfoMessage(gs.getMessage('Related Incidents Resolved'));
action.setRedirectURL(current);
}
}
else
{
return false;
}
}

 

find_real_file.png

find_real_file.png

You are using server side code in the client side.

Try the below script and see if it works

function resolveIncidents() {
    var answer = confirm("Please ensure workaround field has been updated before resolving related incidents.");
    if (answer == true) {
        gsftSubmit(null, g_form.getFormElement(), 'resolveincidents');
} else {
    return false;
}
}

if (typeof window == 'undefined')
    resolveIncidentFunction();

function resolveIncidentFunction() {

    var incident = new GlideRecord("incident");
    incident.addQuery("problem_id", "=", current.sys_id);
    incident.addQuery("incident_state", "=", IncidentState.AWAITING_PROBLEM);
    if ((typeof IncidentReason) !== "undefined")
        incident.addQuery("hold_reason", "=", IncidentReason.AWAITING_PROBLEM);
    incident.query();
    while (incident.next()) {
        incident.incident_state.setValue(IncidentState.RESOLVED);
        incident.close_notes = 'This incident is resolved based on workaround provided in related problem investigation number ' + current.number + '.' + ' The Workaround is ' + '(' + current.work_around + ')';
        incident.close_code = 'solved_workaround';
        incident.update();
        gs.addInfoMessage(gs.getMessage('Related Incidents Resolved'));
        action.setRedirectURL(current);
    }
}

Thank you very much. It is working now perfectly. 

Does it work on workspace?