Once sub task is closed then parent task state should change to work in progress

Talari Balateja
Tera Expert

Hi,

 

I'm looking into requirement. once the subtask is closed then parent task state should chnage to workinprogress.

 

Please help me to complete this task.

 

Parent: sn_si_incident

child: sn_si_task

 

 

Regards,

Sanju.

13 REPLIES 13

Hi @Anurag Tripathi 

 

SS:

TalariBalateja_0-1708614209719.png

 

Pratiksha2
Mega Sage

Hello @Talari Balateja - 

Please try below code in Business rule:

(function executeRule(current, previous /null when async/ ) {

    var newTasks = new GlideRecord("sn_si_task");
    newTasks.addEncodedQuery(//add encoded query here to match the parent record on child table);
    newTasks.query();
    var flag = false;
    while (newTasks.next()) {
        if (current.state != '3') {
            flag = true;
        }
    }
    if (flag == false) {
 
    var grTask= new GlideRecord("sn_si_task");
    grTask.addEncodedQuery(//add encoded query here to match the parent record on child table);
    grTask.query();
        if(!grTask.next()){       
        var incidentReq = new GlideRecord("sn_si_incident");
        if (incidentReq.get(current.number)) {
            incidentReq.setValue('state', '//state number for WIP');
           incidentReq.update();
        }
        }
    }
})(current, previous);

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Pratiksha

Hi @Pratiksha2 

 

I update code like and it's not working. BR AFTER & CONDITION IS STATE CHANGES TO CLOSED COMPLTE

 

(function executeRule(current, previous /*null when async*/) {

var newTasks = new GlideRecord("sn_si_task");
newTasks.addEncodedQuery('state', 'Closed Complete');
newTasks.query();
var flag = false;
while (newTasks.next()) {
if (current.state != '3') {
flag = true;
}
}
if (flag == false) {
var grTask= new GlideRecord("sn_si_task");
grTask.addEncodedQuery('state', 'Closed Complete');
grTask.query();
if(!grTask.next()){
var incidentReq = new GlideRecord("sn_si_incident");
if (incidentReq.get(current.number)) {
incidentReq.setValue('substate', '4');
incidentReq.update();
}
}
}

})(current, previous);

Hello @Talari Balateja -
Please create Before Update BR on  sn_si_incident table and remove the CONDITION IS STATE CHANGES TO CLOSED COMPLTE

This will still not work, the ask is that when the task is closed, the parent state should change to work in progress

The portion of script below will query the whgole sn_si_task table and not just created for that parent

var newTasks = new GlideRecord("sn_si_task");
newTasks.addEncodedQuery('state', 'Closed Complete');
newTasks.query();
var flag = false;
while (newTasks.next()) {
if (current.state != '3') {
flag = true;
}

 

 

 

And then 

-Anurag