- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 05:47 AM - edited 02-26-2024 05:47 AM
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);
}
Please assist.
Thanks & Regards.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 05:50 AM - edited 02-26-2024 05:58 AM
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);
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 06:03 AM - edited 02-26-2024 06:14 AM
Hi @Joshuu ,
First you will need to find the count of total test cases and then how many of them are in passed state. If both the count are same then update the enhancement status.
Please use the below code -
var count = 0;
var count1= 0;
var ga = new GlideAggregate('tm_test_case_instance');
ga.addQuery('parent', current.sys_id);
ga.addAggregate('COUNT');
ga.query();
if(ga.next()) {
count = ga.getAggregate('COUNT');
}
var gaCase = new GlideAggregate('tm_test_case_instance');
gaCase.addQuery('parent', current.sys_id);
gaCase.addQuery('execution_status','passed');
gaCase.addAggregate('COUNT');
gaCase.query();
if(gaCase.next()) {
count1 = gaCase.getAggregate('COUNT');
}
if(count==count1) {
current.state = '10';
current.update();
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 06:41 AM
Hi @Joshuu
I've made changes to the code, could you please use this logic.
var testCases = new GlideRecord('tm_test_case_instance');
testCases.addQuery('parent', current.sys_id);
testCases.query();
// Initialize a flag to track whether all test cases are in 'Passed' state
var allPassed = true;
// Check the status of each linked test case
while (testCases.next()) {
if (testCases.getValue('execution_status') !== 'passed') {
// If any test case is not in 'Passed' state, set the flag to false and break out of the loop
allPassed = false;
break;
}
}
if (allPassed) {
// If all linked test cases are in 'Passed' state, update the Enhancement record's state to 'Deployment'
current.state = '10'; // 'Deployment' state
current.update();
action.setRedirectURL(current);
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thank you!
Subhashisr7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 01:22 AM
Hi @Subhashis Ratna @Aman Kumar S @Anirudh Pathak .
Can we also add an alert to this as below?
"Enhancement record can not be moved to deployment unless all test cases attached to it are in Passes status."
Please assist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 01:36 AM - edited 02-27-2024 01:45 AM
Hi @Joshuu ,
Please try the below code -
var count = 0;
var count1= 0;
var ga = new GlideAggregate('tm_test_case_instance');
ga.addQuery('parent', current.sys_id);
ga.addAggregate('COUNT');
ga.query();
if(ga.next()) {
count = ga.getAggregate('COUNT');
}
var gaCase = new GlideAggregate('tm_test_case_instance');
gaCase.addQuery('parent', current.sys_id);
gaCase.addQuery('execution_status','passed');
gaCase.addAggregate('COUNT');
gaCase.query();
if(gaCase.next()) {
count1 = gaCase.getAggregate('COUNT');
}
if(count==count1) {
current.state = '10';
current.update();
action.setRedirectURL(current);
}
else {
gs.addErrorMessage('Enhancement record can not be moved to deployment unless all test cases attached to it are in Passes status.');
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 01:43 AM - edited 02-27-2024 01:44 AM
Hi @Joshuu
Yes we can . Here i Updated the code based upon your Requirement .
var testCases = new GlideRecord('tm_test_case_instance');
testCases.addQuery('parent', current.sys_id);
testCases.query();
// Initialize a flag to track whether all test cases are in 'Passed' state
var allPassed = true;
while (testCases.next()) {
if (testCases.getValue('execution_status') !== 'passed') {
// If any test case is not in 'Passed' state, set the flag to false and break out of the loop
allPassed = false;
break;
}
}
if (allPassed) {
// If all linked test cases are in 'Passed' state, update the Enhancement record's state to 'Deployment'
current.state = '10'; // 'Deployment' state
current.update();
action.setRedirectURL(current);
} else {
// If any test case is not in 'Passed' state, set an error message and abort the action
gs.addErrorMessage('Enhancement record cannot be moved to deployment unless all test cases attached to it are in "Passed" status.');
current.setAbortAction(true); //To Abort the Action
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thank you!
Subhashisr7