UI Action query

Joshuu
Kilo Sage

Hi All,

 

We have a UI action on enhancement form, I have written the below script to check the related list test cases on the enhancement record.

 

requirement is to check the test cases status, the Enhancement should go into deployment state only if all the test cases linked to the record are in passed state. But with the below script it is checking only one test case. means even if we have multiple test cases without passed state it is moving further.

 

 

var gr = new GlideRecord('tm_test_case_instance');
gr.addQuery('parent', current.sys_id);
gr.addQuery('execution_status', 'passed');
gr.query();
while (gr.next()) {
    current.state = '10';
    current.update();
    action.setRedirectURL(current);
}

 

 

priyarao_0-1708955104412.png

priyarao_1-1708955126853.png

Please assist.

 

Thanks & Regards.

 

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Hi @Joshuu 

Update your script as below:

 

 

var totalCOunt = 0;
var passedCount = 0;
var gr = new GlideAggregate('tm_test_case_instance');
gr.addAggregate("COUNT");
gr.addQuery('parent', current.sys_id);
gr.addQuery('execution_status', 'passed');
gr.query();
if(gr.next()) {
totalCOunt = gr.getAggregate("COUNT");
  }
}
var gr1 = new GlideAggregate('tm_test_case_instance');
gr1.addAggregate("COUNT");
gr1.addQuery('parent', current.sys_id);
gr1.query();
if(gr1.next()) {
passedCount = gr1.getAggregate("COUNT");
  }
}
if(passedCount  ==totalCOunt ){
     current.state = '10';
    current.update();
action.setRedirectURL(current);
}
    

 

 

Best Regards
Aman Kumar

View solution in original post

10 REPLIES 10

Aman Kumar S
Kilo Patron

Hi @Joshuu 

Update your script as below:

 

 

var totalCOunt = 0;
var passedCount = 0;
var gr = new GlideAggregate('tm_test_case_instance');
gr.addAggregate("COUNT");
gr.addQuery('parent', current.sys_id);
gr.addQuery('execution_status', 'passed');
gr.query();
if(gr.next()) {
totalCOunt = gr.getAggregate("COUNT");
  }
}
var gr1 = new GlideAggregate('tm_test_case_instance');
gr1.addAggregate("COUNT");
gr1.addQuery('parent', current.sys_id);
gr1.query();
if(gr1.next()) {
passedCount = gr1.getAggregate("COUNT");
  }
}
if(passedCount  ==totalCOunt ){
     current.state = '10';
    current.update();
action.setRedirectURL(current);
}
    

 

 

Best Regards
Aman Kumar

Hi @Aman Kumar S ,

 

it should update the enhancement form state only, not test case record status.

@Joshuu 

Updated the script, check now

Best Regards
Aman Kumar

Hi @Aman Kumar S ,

 

Thank you. It is working as expected.