Ui action

vikaskv
Tera Contributor

function onResolve() {

    var ga = new GlideAjax('ProblemResolveUtils');

    ga.addParam('sysparm_name', 'check');

    ga.addParam('sysparm_problem_id', g_form.getUniqueValue());

 

    ga.getXMLAnswer(function(response) {

        alert('Received answer: ' + answer); // Client-side debug: shows the response from GlideAjax

 

        if (answer === 'true') {

            var dialog = new GlideModal('resolve_linked_incidents_modal');

            dialog.setTitle('Resolve Linked Incidents');

            dialog.setPreference('width', '1000');

            dialog.render();

        }

    });

 

    if (!g_form.hasField("state") || !g_form.hasField("resolution_code")) {

        getMessage('Cannot resolve the Problem as at least one of the following fields are not visible: \'State\' \'Resolution code\'', function(msg) {

            g_form.addErrorMessage(msg);

        });

        return false;

    } else {

        gsftSubmit(null, g_form.getFormElement(), 'move_to_resolved');

 

    }

}

 

if (typeof window == 'undefined')

    resolveIncidentFunction();

 

function resolveIncidentFunction() {

    current.state = 106;

 current.resolution_code = g_scratchpad.RESOLUTION_CODES.FIX_APPLIED;

    current.update();

}

 

PRB-Resolve incident action

 

Description

 

As the Problem process owner, when a problem record is resolved, I'd like a popup window to appear, to ask if I'd want all related incidents resolved also. So as incidents are not resolved automatically without confirmation from PM.

 

+

 

* Acceptance criteria</>

 

Verdana

 

8pt

 

AS

 

三三三

 

AC1-Given a user clicks the "resolve" button, a popup window will appear "Do you want to resolve all related incidents?"

 

AC2-Given the popup window has appeared, the user should have 2 options "Yes/No"

 

AC3-Given the use clicks yes, all incidents are resloved. If they choose no, no action is carried on the problem state 

 

Here everything works fine but when I click on ui action the problem is not moving to resolve but related incidents are resolved the ui action is oob and i have override it 

 

 

1 REPLY 1

Satyapriya
Mega Sage

Hello @vikaskv ,

Can you please try this code in the ui action and make sure to use the correct value of the resolved state in incident.

// ---------------- CLIENT SIDE ----------------
function onClick() {
// Ask if user wants to resolve linked incidents as well
var answer = confirm("Do you want to resolve all related incidents as well?");
if (answer) {
// YES → run server code to resolve incidents AND Problem
gsftSubmit(null, g_form.getFormElement(), 'move_to_resolved');
} else {
// NO → run server code to only resolve Problem
gsftSubmit(null, g_form.getFormElement(), 'move_to_resolved_no_inc');
}
return false;
}

// ---------------- SERVER SIDE ----------------
if (typeof window === 'undefined') {
// YES – resolve linked incidents AND the problem
if (action === 'move_to_resolved') {
resolveLinkedIncidents(current.sys_id);
current.state = 106; // Resolved
current.resolution_code = gs.getProperty('problem.default.resolution_code', 'fix_applied');
current.update();

// NO – resolve only problem
} else if (action === 'move_to_resolved_no_inc') {
current.state = 106;
current.resolution_code = gs.getProperty('problem.default.resolution_code', 'fix_applied');
current.update();
}
}

// Helper function
function resolveLinkedIncidents(problemSysId) {
var inc = new GlideRecord('incident');
inc.addQuery('problem_id', problemSysId);
inc.addQuery('state', '!=', '7'); // Not already closed
inc.query();
while (inc.next()) {
inc.state = 6; // Resolved
inc.close_code = 'Closed/Resolved by Problem';
inc.update();
}
}