UI action gsftsubmit()

akashsingh20234
Tera Contributor

 

create a ui action to close incident state when all the incident task is cloes complete if any task is not close complete then will not be able to close the state and print a msg please close task incident first?

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @akashsingh20234 ,

I tried your problem in my PDI and I hope this code helps you, Please create UI Action which is client callable and add below code 

function incidentClose() {
    var state = [];
    var gr = new GlideRecord('incident_task');
    gr.addQuery('incident', g_form.getUniqueValue());
    gr.query();
    while (gr.next()) {
        state.push(gr.state.toString()); // There are multiple incidnet tasks
    }

    for (i = 0; i < state.length; i++) {
        alert("Inside for = " + state[i]);
        if (state[i] != state[i - 1]) {
            alert('All the Incident Task Values are not Close Complete ');
        } else {
            if (state[i] == 3) {
                alert("CLosing the Incident bcoz all the Incident task are Close Complete ");
                current.state = '7';
                current.update();
            }

        }
    }
}

 

Result 

Scenerio 1 : When Incident Task is not close complete 

SarthakKashya2_0-1712944779442.png

 

 Scenerio 2: When Incident Tasks are close compelte 

SarthakKashya2_1-1712945016361.png

 

SarthakKashya2_2-1712945036866.png

 

All the incindet tasks are complete 

 

Please mark my ans correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

View solution in original post

2 REPLIES 2

Jayant_M
Kilo Sage

Hi @akashsingh20234 ,

 

Please refer the below code :

 

var rec = new GlideRecord('incident_task');

rec.addQuery('incident', current.sys_id);

rec.addQuery('state', '3');

rec.query();

gs.info('Open Tasks' + rec.getRowCount());

if(rec.next()){

gs.info('Inside if');

gs.addErrorMessage('All incident taks should be closed before resolving/closing incidnet ' + current.number + ' record'); // use valid number field

current.setAbortAction(true);

}
else
{
current.state = '3';
current.update();

action.setRedirectURL(current);
}

Please mark my response helpful if it resolves your issue!

Community Alums
Not applicable

Hi @akashsingh20234 ,

I tried your problem in my PDI and I hope this code helps you, Please create UI Action which is client callable and add below code 

function incidentClose() {
    var state = [];
    var gr = new GlideRecord('incident_task');
    gr.addQuery('incident', g_form.getUniqueValue());
    gr.query();
    while (gr.next()) {
        state.push(gr.state.toString()); // There are multiple incidnet tasks
    }

    for (i = 0; i < state.length; i++) {
        alert("Inside for = " + state[i]);
        if (state[i] != state[i - 1]) {
            alert('All the Incident Task Values are not Close Complete ');
        } else {
            if (state[i] == 3) {
                alert("CLosing the Incident bcoz all the Incident task are Close Complete ");
                current.state = '7';
                current.update();
            }

        }
    }
}

 

Result 

Scenerio 1 : When Incident Task is not close complete 

SarthakKashya2_0-1712944779442.png

 

 Scenerio 2: When Incident Tasks are close compelte 

SarthakKashya2_1-1712945016361.png

 

SarthakKashya2_2-1712945036866.png

 

All the incindet tasks are complete 

 

Please mark my ans correct and helpful if this works for you

 

Thanks and Regards 

Sarthak