Calculated Field using SIL script - how to filter subtasks

Chris Chambers September 13, 2018

I'm using a calculated field to present the percent complete of a task - percent is based on the number of sub-tasks in the DONE status.

Using a SIL script I'm able to retrieve the # of sub-tasks of a parent task, but now I need to determine which of those subtasks have a status of DONE.  I tried JQL - it just returned every sub-task of every parent task in the entire project that was in the DONE status; I don't think you can use a variable in JQL query, so only a static search would work when I'd tried filtering THIS SPECIFIC TASK'S sub-tasks.

I've given up on trying to use JQL filters in my SIL script, and have the script below.  But I keep getting "lexical" errors, when trying to save it.  Can someone please review, and let me know where I've gone off track? I've commented out the test lines I've attempted, whether they've failed or succeeded, just to illustrate what I've tried thus far.

Thank you,

Chris

--------------

// script to calculate percent of Parent Task complete based on # of completed subtasks.
//
number subtaskCount = size(subtasks(key)); // number of subtasks of parent issue
string [] allSubs = subtasks(key); // string with keys of all parent's subtasks ? I think?
number doneCount = 0;
for (string eachTask in allSubs){
if (status = 'DONE') {
// if (%eachTask%.status = 'DONE'){
// if (%eachTask%.status = "DONE"){
doneCount = doneCount + 1;
}
}
number prctDone = ((doneCount / subtaskCount) * 100);
//return "num of subtasks " + subtaskCount;
//return "num of subtasks in DONE " + doneCount; // IF this works, it ALWAYS returns 0
return "Percent complete: " + prctDone;

 

 

1 answer

1 accepted

2 votes
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2018

Hello,

It should be like this:

// script to calculate percent of Parent Task complete based on # of completed subtasks.
//
number subtaskCount = size(subtasks(key)); // number of subtasks of parent issue
string [] allSubs = subtasks(key); // string with keys of all parent's subtasks ? I think?
number doneCount = 0;
for (string eachTask in allSubs){
//if (status = 'DONE') {
// if (%eachTask%.status = 'DONE'){
if (%eachTask%.status == "DONE"){
doneCount = doneCount + 1;
}
}
number prctDone = ((doneCount / subtaskCount) * 100);
//return "num of subtasks " + subtaskCount;
//return "num of subtasks in DONE " + doneCount; // IF this works, it ALWAYS returns 0
return "Percent complete: " + prctDone;
Chris Chambers September 13, 2018

that worked.  thank you!  

[ crawls back under desk - embarrassed didn't realize it should be == instead of = ]

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2018

You are welcome! :)

Christopher Gronde June 7, 2019

When I try to run this it does not like line 6 with the "for" statement and I always get a null response

konikris October 8, 2019

Hi Christopher,

 

Can you help me where i need to place the SIL Script and how this script will be executed.

Any doc with the steps how to run this script.

 

Thanks in Advance!

Suggest an answer

Log in or Sign up to answer