It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Calculated Field using SIL script - how to filter subtasks

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

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;

that worked.  thank you!  

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

You are welcome! :)

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

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
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

261 views 1 2
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you