Forums

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

JMWE: calculated field for a date and a number field

Javanshir Mustafayev _ HIT
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.
October 6, 2022

Hi, I need to have a calculated field that will:

Take the date from Field A and minus the value from Field B

Write the outcome date to Field C

is it possible?

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
October 6, 2022

Hi @Javanshir Mustafayev _ HIT ,

what is field B supposed to represent? A number of dayshours, seconds, ...?

Also, where are you trying to use that calculation? A Set Issue Fields post-function?

Javanshir Mustafayev _ HIT
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.
October 6, 2022

Hi @David Fischer Field B is a number field, that represents days. And is to be used to minus it's value from Field A which is a date picker field

David Fischer
Community Champion
October 6, 2022

Then the Nunjucks expression you're looking for is:

{{issue.fields["A"] | date('subtract', issue.fields["B"] , "days") | date }}
Javanshir Mustafayev _ HIT
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.
October 7, 2022

@David Fischer thanks for your help, the script above works, but could you please help me trim the value

from:

2031-07-28T00:00:00+00:00

to:

2031-07-28

?

Javanshir Mustafayev _ HIT
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.
October 7, 2022

Also, if I remove either Field A or Field B values, I wish the Field C to be cleared and be empty, if possible, please

David Fischer
Community Champion
October 7, 2022

@Javanshir Mustafayev _ HIT if you are writing this value to a Date Picker field, the value will be "trimmed" automatically by Jira.

As for returning an empty value when one of the source fields is empty, you can do this:

{% if issue.fields["A"] and issue.fields["B"] %}
{{issue.fields["A"] | date('subtract', issue.fields["B"] , "days") | date }}
{%endif%}
Javanshir Mustafayev _ HIT
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.
October 7, 2022

@David Fischer the values aren't removed if any of the fields is emptied. The read-only field stays untouched with the previously calculated value.

Also, Jira isn't trimming because I'm using a read-only text field, is there a workaround or the field should be a date field to be trimmed?

Javanshir Mustafayev _ HIT
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.
October 7, 2022

@David Fischer I've changed the field type to a date picker, and hid it on the screen configs, now all works as expected, thanks

David Fischer
Community Champion
October 9, 2022

@Javanshir Mustafayev _ HIT 

FYI, you cannot clear a read-only text field, it's a Jira Cloud limitation.

Suggest an answer

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

Atlassian Community Events