Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Automation to Check Time in Story and Subtask before Deleting

Jason Krewson
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.
August 30, 2024

We normally allow project leads and certain users the ability to delete issues in Jira but recently we have had an outbreak of users deleting issues with time logged to them and that is a big issue so in the short term I have disabled the ability to delete cards for everyone. 

Long term possible solution is: 

  • No one has the ability to delete. 
  • We introduces a new status, To be Deleted, we allow project leads to move cards to this status. 
  • When a card is moved to the To be Deleted Status automation runs a check on it and actions it depending on what it finds (picture below of the automation). 
    • If it has timespent automation moves the card back to In Progress and emails the assignee letting them know that the card has timespent on it so we are unable to delete, contact the Jira team if you need more help. 
    • If it has no timespent the automation deletes it.

Screenshot 2024-08-30 132401.png

The issue is, what if this is a Story and the Subtask has time?

So first thought was just use sigma timespent and that solves the issue, but after checking the automation possibilities and researching online I am finding that isn't possible.  

I also tried to have it check the subtask for matches with time, but this also doesn't seem possible. 

So the question would be, is there a way to have this automation also verify the Subtask doesn't have time as well before deleting?

1 answer

1 accepted

1 vote
Answer accepted
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 30, 2024

Hello @Jason Krewson 

Yes!

After the trigger add a Lookup Issue action to search for subtasks under the trigger issue where the subtask  has Timespent

Screenshot 2024-08-30 at 1.09.30 PM.png

(If this is for a Team managed project, use Subtask instead of Sub-task.)

Then in your IF-Else block in the first IF where you are checking for Timespent on the issue, change the condition set to be "Any of" and add this smart value condition

Screenshot 2024-08-30 at 1.12.32 PM.png

If any subtasks with Timespent are found, then the size of of result set in Lookup Issues will be greater than 0.

So if either a subtask has Timespent or the main issue has Timespent, transition the main issue back to In Progress.

Jason Krewson
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.
August 30, 2024

Thanks so much for the reply and help, I didn't think I would get a response so fast. 

I have tested, below screenshot is the changes I made off your suggestion, and its still deleting the Story and Subtask when the Story has no time but each Subtask has 1 hour in it. 

For testing I am doing 1 Story with no time that has 2 Subtasks with 1 hour each.

Screenshot 2024-08-30 154601.png

Maybe I did something incorrect?

This is Jira Cloud also, I forgot to mention this in my first post. 

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 30, 2024

Hello @Jason Krewson 

It looks like you are missing a curly brace before triggerIssue in the JQL also - there should be two curly braces.

Screenshot 2024-08-30 at 2.07.04 PM.png

After fixing that, please test it again.

If it still does not work correctly then there may be something else wrong with the JQL.

Is the project to which the rule applies a Company Managed project or a Team Managed project? The subtask issue type name in the Lookup Issues JQL needs to be correct for that project type.

Can you confirm that the Lookup Issues JQL is finding the subtasks by substituting the issue key of your test issue where the JQL currently has {{triggerIssue.key}}, and then click the Validate Query link below and to the right.

Screenshot 2024-08-30 at 2.10.42 PM.png

If that says there are 0 issue then you should go to the View All Issues page and work out the JQL details to make sure it is correct for retrieving the subtasks you expect. The only difference between the JQL there and in the rule would be the use of the smart value for the trigger issue key.

 

If it still doesn't work, please share new images of the changes you've made and  share the rule execution log output

 

Jason Krewson
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.
August 30, 2024

It seems to be this part that is causing the issue, moment I remove it I can validate the JQL query, if I leave it in I cannot click on validate query. 

parent = {{triggerIssue.key}} and

This is a global rule but all our projects are company managed.

When I look through smart values, I cannot find {{triggerIssue.key}}.

1.png2.png

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 30, 2024

Hello @Jason Krewson 

The Validate Query can't be used when you have a smart value in the query. That is why I asked you to substitute in the actual issue key as a test.

Can you confirm that the Lookup Issues JQL is finding the subtasks by substituting the issue key of your test issue where the JQL currently has {{triggerIssue.key}}, and then click the Validate Query link below and to the right.

 

Information about the smart value {{triggerIssue}} can be found here:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/#--triggerIssue--

It is a way to refer to the issue that triggered the rule, regardless of the current context of the rule at the moment of the reference. You can use {{triggerIssue}} anywhere that you could use {{issue}} to get at the values in the rule's trigger issue.

 

Did you go to the View All Issues page to validate that the JQL, with an actual issue key after parent= , returns the subtasks you would expect for the specified issue?

Jason Krewson
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.
August 30, 2024

Thanks for the information on this, it does return the correct subtasks when I swap it out with one of the parents. 

parent = DELETE-20 and issuetype = Sub-task and Timespent is not empty

I tested again moving the parent Delete-20 to To Be Deleted status and it deleted the Story and the Subtasks.

We do use Tempo for time tracking, but this does add time to Timespent, that is why the automation works for just the Story (and JQL above for Subtasks), just couldn't figure it out for the Subtasks, but we are on the right track. 

 

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 30, 2024

So for DELETE-20 there were Sub-tasks for which Timespent was not empty, and it was deleted anyhow by the rule?

Please share the rule execution audit log details from the rule execution where DELETE-20 and its subtasks were deleted.

Jason Krewson
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.
August 30, 2024

Correct and below is the log from when it deleted it. 

Screenshot 2024-08-30 191312.png

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 30, 2024

According to the log the issue is not matching the conditions on the IF, so it moves on to the ELSE-IF which it does match and the issue gets deleted.

In the IF it looks like for the smart value you may have used {{lookupissues... with a lower case "i". It needs to be an upper case "I". If it is not upper case please make that change and test again.

If that does not resolve the issue, again please provide the log output and also please an image of the details of the IF conditions.

Jason Krewson
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.
August 30, 2024

Yep it was i not I, so I updated it to the below. 

{{lookupIssue.size|0}}

It ended up deleting it again. 

Screenshot 2024-08-30 200250.png

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 30, 2024

It also has to be plural, as in the example I provided.

{{lookupIssues.size|0}}

Jason Krewson
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.
August 31, 2024

Good catch, I wont’t be able to update this and test again untill Thursday. Thanks for all your help on this, I will update again the moment I test and will let you know the results. 

Jason Krewson
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 5, 2024

@Trudy Claspill I just got back from vacation, updated "{{lookupIssues.size|0}}" correctly, tested, and it worked! 

I will do some more testing and let you know but this is great!

 

Jason Krewson
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 5, 2024

Testing went well, I tested every combination I could think of and it only deleted when there as no time in the Story and the subtask so its perfect. 

Thanks again for all the help @Trudy Claspill 

Below is what the final automation looks like. 

Screenshot 2024-09-05 123353.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events