Automation for Jira: Logging Time Spent with Automation Rules

Jeffrey Bistrong
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.
January 5, 2020

Summary

I am beginning to log time spent on our support tickets using Jira Service Desk and Automation for Jira. I have taken a look at the existing plugin for our billing app "Harvest" and the functionality is sub par for our needs, so I've decided to automate the recording of timepent, however, I am getting an error "AS-6558 (Invalid time duration entered. (worklog_timeLogged))." in the second automation rule.

 

Logic of Automation Rules

 

Rule 1: When ticket is transitioned from any status to "In progress", I have a field (only available on the edit screen) called "Timestamp_for_billing", I set the timestamp to {{now}} which records the timestamp the user begins working on this issue.

 

Rule 2: When the ticket is transitioned from "In Progress" to any other status, I have an automation rule with the following logic that is throwing the error mentioned the summary above.

 

{
"update": {
"worklog" : [
{
"add": {
"timeSpent" : "{{now.diff(issue.Timestamp_for_billing).minutes}}m"
}
}
]
}
}

 

Any ideas of what I am doing wrong, or if anyone has a better way to do this, I am open to suggestions.

 

Thanks in advance!!

3 answers

1 accepted

3 votes
Answer accepted
Jeffrey Bistrong
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.
January 6, 2020

Per suggestion above, In the case of your smart value, can you try swapping the positions of now and issue.Timestamp_for_billing to see if that makes a difference." fixed the issue.

Mitchell Cole February 17, 2022

Can you post the full working code for this please? There are a few combinations of which way that can go and it would be great to see this working as I'm trying to do exactly the same thing as you. 

Thank you!

Jeffrey Bistrong
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.
February 17, 2022

I have two automation rules 

 

Rule 1.  - adds the now timestamp when the issue is triggered to "in progress"

timespent1.png

 

 

Rule 2 - does the calculation to add to time spent. One thing I want to note is the last edit action (which will also clear out the value in timestamp for billing) so you don't get accidental calculations 

timespent2a.pngtimespent2.png


{
"update": {
"worklog" : [
{
"add": {
"timeSpent" : "{{issue.Timestamp_for_billing.diff(now).minutes}}m"
}
}
]
}
}

Like Mitchell Cole likes this
Mitchell Cole February 18, 2022

Thanks mate, really appreciate this. Especially the response, life saver!

1 vote
Ansar Rezaei
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.
January 5, 2020

If you have JIRA Workflow Toolbox, You could find the complete guide here:
https://apps.decadis.net/display/JWT/Automatic+work+log+with+start+and+stop+work+transitions

If you have to do it with automation for JIRA, please explain it more and say what's worklog_timeLogged field type and where and how you set it? 

Jeffrey Bistrong
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.
January 6, 2020

Hi Ansar, thanks for the tip, I don't have JIRA Workflow Toolbox, and was able to accomplish this in Automation for JIRA. 

 

 worklog_timeLogged is a default field in JIRA and is used for time tracking. I found references on how to update these fields from the automation for jira documentation: https://docs.automationforjira.com/issues/edit-additional-fields.html#field-syntax-examples

0 votes
Jeffrey Bistrong
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.
January 5, 2020

I did some additional troubleshooting by having Automation for Jira return the value from 

{{now.diff(issue.Timestamp_for_billing).minutes}

To return the value in a free text field to see what it was spitting out, and the value returned was "-20"

 

What am I doing wrong here, it should return a positive value. 

Simmo
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 5, 2020

Hi Jeffrey,

Thee easiest way to test and fine tune your smart values is to use the Log action which will output the value to the audit log.

In the case of your smart value, can you try swapping the positions of now and issue.Timestamp_for_billing to see if that makes a difference.

Finally, you can use the Log work action to add timeSpent and that will be much easier than using the Edit action.

Cheers,

Simeon.

Jeffrey Bistrong
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.
January 6, 2020

@Simmo thanks for the tip about using the log action (good to know for the future).

 

Yes, swapping the positions of the now and "issue.Timestamp_for_billing " did the trick, I didn't think that would work when I originally thought of that idea. Silly me, I should have tested it anyway. 

 

Thanks for the tip and I am now up and running. 

Simmo
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 6, 2020

No worries, glad you're all sorted!

Suggest an answer

Log in or Sign up to answer