Automation vacation and sick\leave days

Denys Mokhynia April 6, 2023

Our organisation use Timetracker for log working time. 

Timetracker use standart worklog and estimate time.

We have 2 type of users - new and old.

We have project with sick\leave task for every users. When they need vacation or sick they log time to this their tiket.

New user

In half year from their start have +5 Days for vacation\leave and + 0,5 year - add +10 Days. And every half year after their start they have +5 Days and year +10. 

Maximum 15 days total.

Old user

1st january have +15 days for the year, and every year it refresh.

HR asked me to create system based on this tickets - show how much Days (vacation\leave) everybody have.

I created custom fields 

Days - for calc days, how much it left

DaysOff - for calc how much days they Used

AddsCounter - is stop for add everyday Days (1 or 2)

Also for every User we add StartDate in tasks. For New its day of their start. For Old we set this date as 01.01.2021

DueDate - I use for check how much time spent, and i change it on {{duedate.plusyears(1)}} when it spent 1y and we add them +10 Days

1st script easy:

Screenshot 2023-04-06 at 14.19.31.png

For correct Days no more than 15. If something not used and total stay >15.

2nd script add +5 Days (0,5y) +10 Days (1y) and I added - AddsCounter wich = 1 or 2. It sheduled on everyday at 9 am

Screenshot 2023-04-06 at 14.24.44.png

1st part its for New users and Old(DueDate alwas 01.01.20XX) 

Screenshot 2023-04-06 at 15.04.23.png

It set UsedDays - 0 AddCounter - 0 and when DueDate > 1y than today it change it too.

This 2 scritps working, maybe I will optimise it.

I have issue with calc Days when guys Add, Del it or change.

3rd script

It correct Days and UsedDays when somebody changed worklog (Timetracker)

" {{Days}}-{{#issue.worklog.timeSpentSeconds.sum}}{{fromString}}-{{toString}}{{/issue.worklog.timeSpentSeconds.sum}})/28800 

{{UsedDays}}+({{#issue.worklog.timeSpentSeconds.sum}}{{fromString}}-{{toString}}{{/issue.worklog.timeSpentSeconds.sum}})/28800 "

Screenshot 2023-04-06 at 15.15.26.png

Need +Days when worklog minus

And +UsedDays when worklog plus

And edit to + or -.

Log show me

Could not convert the field value to a number. Please ensure the value is a number, math expression or smart-value that can be converted into a number.
UsedDays: 0.0+65220)/28800
Maybe somebody can help with script or Apps, that can solve this request with such system of add vacations\days-off

3 answers

0 votes
Denys Mokhynia April 11, 2023

I dont know how to do it. I want to do it but math not helped.

{{#=}}{fieldA}}+{{fieldB}}{{/}}
0 votes
Béla Hegyesi April 7, 2023

Hi @Denys Mokhynia

First of all, you can use number fields for your Days and Daysoff fields.
I would implement a "Log action" step after every step in your Automation rule, so you can see, what's happening in the background.

As @Bill Sheboy said, you'll have to indicate, that you are defining a math expression.

Have a nice day,
Bela

0 votes
Bill Sheboy
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.
April 6, 2023

Hi @Denys Mokhynia -- Welcome to the Atlassian Community!

It can help for a question like this to include an image of the audit log details for the rule execution.  That will provide context for where the error is happening in the rule.

Next, you are trying to set values using mathematical expressions.  Please try wrapping those with the math operator, such as like this:

{{#=}}{fieldA}}+{{fieldB}}{{/}}

The specific error you show seems to indicate a missing parenthesis in the expression.  Please check if those are all paired up correctly.

Finally, this is a complicated use case for automation rules.  I recommend periodically writing the expressions to the audit log to confirm they are working as you expect.  That may help narrow down where the problem exists.

Kind regards,
Bill

Denys Mokhynia April 11, 2023

Hm, i will try to check rule on parenthesis. 

Denys Mokhynia April 11, 2023

How Can I check worklog

If I have 2 worklog days

I loged 1 day

How i can calculate this 1 day

{{#worklog.timeSpentSeconds}}{{fromString}}-{{toString}}{{/worklog.timeSpentSeconds}}

This formula?

I want to understand if I add 1d

system +1

If I minus 1d

system -1

or it always will show 1 without "-" or "+"

I need when worklog created +1d

Days -1d

UsedDays +1d

When worklog delete -1d

Days +1d

UsedDays -1d

When worklog edited "+0,5d" or "-0,5d" (1d,2d etc)

System understand it and 

"+" or "-" Days, UsedDays

Bill Sheboy
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.
April 11, 2023

First thing: please try to stick to one conversation thread when responding.  Otherwise it becomes difficult to follow and readers often understanding that each thread is a solution approach to try.  Thank you.

You note that you tried the math operation syntax and that did not work.  Please post images of your current rule, showing your use of the math operation.  That may help to explain what is happening.

Denys Mokhynia April 12, 2023

Sorry, I think I wrote what I need.
I add math model, yes it not gived errors but  Days it calculate correct when I deleted worklog, it showed it do "-1". But UsedDays the same formula not counted, at all 

{{#=}}{{Days}}-({{#issue.worklog.timeSpentSeconds}}{{fromString}} - {{toString}}{{/issue.worklog.timeSpentSeconds}})/28800{{/}}
 {{#=}}{{UsedDays}}+({{#issue.worklog.timeSpentSeconds}}{{fromString}} - {{toString}}{{/issue.worklog.timeSpentSeconds}})/28800{{/}}

It look like it missed 2nd rule

Screenshot 2023-04-12 at 11.03.43.png

Maybe I explain wrong.

I need bulid 1 rule for my system that understand and calculate 2 custom fields

Days and UsedDays, as i wrote in last message.

I understand, I think, how it should be when users add worklog and delete worklog(I'ill build 2 rules with create and delete worklog). I think it show mistakes but it will work. But if user edit worklog (2d to 1d), I understand that I will have mistakes in my system. And I want build 1 rule or 3 for Create, Deleate and Edit worlklog. And system should understand 

+ or - Days and UsedDays.

Can u help me with it? If no, so ok. I missied understood rules of best Atlassian community.

Bill Sheboy
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.
April 12, 2023

Is the only case that is not working correctly when a user edits a worklog to decrease the value, such as 2d to 1d?  Or are there more?

Denys Mokhynia April 13, 2023

Yes, in this case

When user add worklog (use timetracker, its the same work as u do it by Jira instruments, but more comfortable), I can create rule 

1st

Create worklog (its +)

Days will be minus

UsedDays will be plus

2nd

Delete worklog (its -)

Days will be plus

UsedDays will be minnus

How to create rule for situation when user edit their worklog, I dont know. He can change from 1.5d to 1d or from 1d to 1.5d. 0.5d to 1d etc.

We did restrict no more that 12h (1.5d) logs per day. But its will not change situation)

 

So i am thinking about that some IF operator use

If user change worklog, is it more or less than last value. And depend of result what user have done it always correct calcilate. If i solve this last issue It cover full actions with work log. 

Than nothing matter +, - or edited user worklog. It always will be correct.

Bill Sheboy
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.
April 13, 2023

Thanks for clarifying.  I am unclear why this would not work so perhaps you can explain further.  For example, your rule is setting...

Days = current Days - (worklog change of fromString - toString)

And so that should work correctly if your values are increasing or decreasing, right?

Increasing: worklog was 1d and is now 2d leads to: current Days - (2d - 1d)

Decreasing : worklog was 2d and is now 1d leads to: current Days - (1d - 2d)

I recommend writing all of the values to the audit log before and after the math operation to confirm what is happening:

  • action: write to audit log Days, worklog fromString, worklog toString
  • action: math operation to update Days
  • action: re-fetch issue (to reload the data)
  • action: write to audit log Days
Like Denys Mokhynia likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events