Forums

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

Do a calculation

Mohamed Eid February 4, 2025

Trying to do a sum of two values I have

The first one is start date and the second is remaining days

Both are written in Jira description custom field

However seems that they are string and cannot be added together

I ve tried to convert them to numbers but could not

So what i am looking for is to do the addition of the date and the number of days to get the expiry date and add it to the summary

 

3 answers

1 vote
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.
February 14, 2025

Hi @Mohamed Eid 

Based on the rule images you are showing, you appear to be using Jira Server or Jira Data Center and not Jira Cloud.  You may confirm that by asking your Jira Site Admin or looking at your URL: if it ends with .atlassian.net or .atlassian.com you are on Jira Cloud.  Otherwise you are on Server or Data Center.

 

One of your Created Variables, named startdate, could be colliding with issue fields.  I recommend always adding a prefix to variable names to avoid such problems, such as varStartDate.

 

Finally, once you confirm your Jira version, there are known problems incrementing a date / time field with a Created Variable value for Jira Data Center...even when converting text to a number.  I believe the only way to solve that matches the earlier suggestion from @Tuncay Senturk to store the value in a number field (either by extraction or from the source) and then use that number field to increment the date value.

 

If none of those suggestions help, please work with your Jira Site Admin to contact the Atlassian Support team for assistance: https://support.atlassian.com/contact/#/

 

Kind regards,
Bill

0 votes
Tuncay Senturk
Community Champion
February 4, 2025

Hi @Mohamed Eid 

Could you elaborate further on the problem you wish to solve? You have both the start date and the remaining days in the issue's description field, and you want to perform a calculation to determine the expiry date; is that correct?

The description field is a text field and can contain a lot of free-format text, which makes implementing such a scenario unreasonable. I would strongly suggest using a separate field for each and conducting the calculation accordingly.

If I am missing anything, could you provide some examples?

Mohamed Eid February 4, 2025

So in Jira task description there is the two values as follows :

-----Q-------

Jira description :

 

The server xxxxx certificate is expiring in 44.9999 days,

 

This started at 2025-01-18 01:00:10 CET, – or 0h 0m ago.

----Unq-----

 

So what I want is to add 2025-01-18 01 and 44.9999 to give me the certificate expiration date which should be 2025-03-03 

Tuncay Senturk
Community Champion
February 4, 2025

I don't believe this is the most effective way to achieve this. I mean, you need to use a regular expression to parse the entire description field, select the relevant parts, and perform the calculations. This is not particularly difficult, but it is quite error-prone. There may be other dates and time indicators; how will they be handled? Additionally, there may be weeks, hours, etc.

As I mentioned earlier, it is best to use separate fields and the appropriate field types (date, number).

Mohamed Eid February 4, 2025

I suppose it should be simple and very reasonable

We have two pieces of info in each ticket description coming with the same format as provided the start date as YYYY-MM-DD and the remaining days until expiry

summing them gives the expiration date which we need to add to the summary

so no other dates or times its only one start date and one remaining days per ticket which gives us one expiration date that will be added to the summary which I could achieve

 

I could add the expiration date in the summary also i could extract both the start date and remaining days from the description and put them in smart variables but the addition/calculation does not work

could you please elaborate more or give an example to follow for the separation field you mentioned ? btw I am using jira automation rule for this

 

thank you

 

Mohamed Eid February 4, 2025

so using this in a log action can extract both the start date and remaining days as follows :

 

Log action: Start Date: {{issue.description.substringAfter("This started at ").substringBefore(" ")}} Remaining Days: {{issue.description.substringAfter("is expiring in ").substringBefore(" days")}}

 

logging the output as :

 

Log
Log action: Start Date: 2025-01-18 Remaining Days: 44.9999
what remains is only the calculation of these two values ( thats what I am currently stuck at )
then adding them to the summary ( which is easy to do )
0 votes
Vishal Biyani
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 4, 2025

@Mohamed Eid 

Look at this link that gives you details about how to add date and number 

Examples of using smart values with dates | Cloud automation Cloud | Atlassian Support

Try this out and see if it works for you

Vishal Biyani
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 4, 2025

@Mohamed Eid 

You can create two smart variables and stored the values that you have parsed. Let's say

1. CertificateIssueDate = {{issue.description.substringAfter("This started at ").substringBefore(" ")}}

2. CertificateExpiringInDays = {{issue.description.substringAfter("is expiring in ").substringBefore(" days")}}

 

Now create 3rd smart variable say CertificateExpirationDate and calculate the Smart value like this

{{#debug}} {{ CertificateIssueDate.toDate("yyyy-MM-dd").plusDays(CertificateExpiringInDays.asNumber)}} {{/}}

 

Note: For your use case I get the value as 2025-03-03

Let me know if this helps you make progress.

 

 

Mohamed Eid February 5, 2025

 

@Vishal Biyani unfortunately it didnt work

I did the following 

created variable and called it startdate with the value as below :

{{issue.description.substringAfter("This started at ").substringBefore(" ")}}

 

then a second variable called remainingdays with the below value :

 

{{issue.description.substringAfter("is expiring in ").substringBefore(" days")}}

 

then a 3rd variable named expirationdate as :

{{#debug}} {{ startdate("yyyy-MM-dd").plusDays(remainingdays.asNumber)}} {{/}}

 

and then used action log with this :

 

{{#debug}} {{ startdate("yyyy-MM-dd").plusDays(remainingdays.asNumber)}} {{/}}

 

and it gave me this 

Log action

Debug message
Log
Vishal Biyani
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 5, 2025

.toDate is missing 

try with this corrected statement:

{{#debug}} {{ startdate.toDate("yyyy-MM-dd").plusDays(remainingdays.asNumber)}} {{/}}

Mohamed Eid February 5, 2025

empty again

VOI_SSL Certificates- -Expiration Date =

Log action

Log
Debug message

Edit issue

Issues edited successfully
VOICE-34562
Debug message
Vishal Biyani
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 6, 2025

@Mohamed Eid 

Share the screen shot of your automation and of the audit log by expanding each action. 

Mohamed Eid February 6, 2025

Image 06-02-2025 at 12.09.jpegImage 06-02-2025 at 12.09 (1).jpegImage 06-02-2025 at 12.10.jpegImage 06-02-2025 at 12.10.jpegImage 06-02-2025 at 12.10 (1).jpegImage 06-02-2025 at 12.10 (1).jpegImage 06-02-2025 at 12.44.jpeg

here they are

Mohamed Eid February 6, 2025

@Vishal Biyani please have a look and let me know

Thank you very much in advance

Vishal Biyani
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 6, 2025

@Mohamed Eid 

can you add debug message for each step where you are creating the smart variable?

share the audit log message in one screen shot

Mohamed Eid February 6, 2025

Image 06-02-2025 at 13.29.jpegImage 06-02-2025 at 13.30.jpegImage 06-02-2025 at 13.30 (1).jpegImage 06-02-2025 at 13.30 (2).jpeg

yes here you are

Mohamed Eid February 6, 2025

@Vishal Biyani please have a look and let me know

thanks again

Vishal Biyani
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 6, 2025

@Mohamed Eid 

Formula looks correct. 

Could you add {{#debug}} {{/}} when you are creating the variables?

Let's see with that additional check to isolate where the problems could be

Mohamed Eid February 7, 2025

@Vishal Biyani here you go Image 07-02-2025 at 09.52.jpeg

Vishal Biyani
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 7, 2025

now add one more log statement like below

startdate with format = {{ startdate.toDate("yyyy-MM-dd") }} and remaining days = {{ remainingdays.asNumber }}

 

This should log the startdate like 2025-01-18T00:00:00.0+0000 and remaining days  should print like 44.9999 correctly.

Let's see if the issue is happening in this step.

Vishal Biyani
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 10, 2025

@Mohamed Eid 

Were u able to check?

Mohamed Eid February 11, 2025

@Vishal Biyani 

 

Log action

Log
startdate with format = 2025-01-18T00:00:00.0+0100 and remaining days =
Vishal Biyani
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 11, 2025

@Mohamed Eid 

Looks like the Regex expression for remaining days is not working. Can you check if this is having any extra spaces or something like that?

if remaining days gets populated i think the rule will work.

To test the theory, you can try hardcoding the value of remaining days and see that you are getting the final output. This is to ensure there is no other issue with the rule other than populating of remaining days

Mohamed Eid February 12, 2025

If I hardcode ramaining days to be 10 it shows it

also if in the plusdays formula i remove remainingdays.asnumber and hardcode it to a difect number like 10 it also works

 

Log
startdate with remaining days hardcoded = 2025-01-18T00:00:00.0+0100 and remaining days = 10

Log action

Log
2025-01-28T00:00:00.0+0100
Debug message
2025-01-28T00:00:00.0+01
startdate with remaining days hardcoded = {{ startdate.toDate("yyyy-MM-dd") }} and remaining days = 10
{{#debug}} {{ startdate.toDate("yyyy-MM-dd").plusDays(10)}} {{/}}
so its clear that the issue is with the remaining days part so how do you think we can resolve it ?
Mohamed Eid February 12, 2025

Hi @Vishal Biyani 

If I hardcode ramaining days to be 10 it shows it

also if in the plusdays formula i remove remainingdays.asnumber and hardcode it to a difect number like 10 it also works

 

Log
startdate with remaining days hardcoded = 2025-01-18T00:00:00.0+0100 and remaining days = 10

Log action

Log
2025-01-28T00:00:00.0+0100
Debug message
2025-01-28T00:00:00.0+01
startdate with remaining days hardcoded = {{ startdate.toDate("yyyy-MM-dd") }} and remaining days = 10
{{#debug}} {{ startdate.toDate("yyyy-MM-dd").plusDays(10)}} {{/}}
so its clear that the issue is with the remaining days part so how do you think we can resolve it ?
Vishal Biyani
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 12, 2025

print remaining days enclosed in pipes

{{ #debug }} |{{ remainingdays }}| {{/}}

if there is any extra character like space, we will know by seeing a gap between the digit and |.

Mohamed Eid February 12, 2025

it doesnt even accept this format

Image 12-02-2025 at 12.15.jpeg

Mohamed Eid February 12, 2025

please make sure the syntax is correct so I can test it

{{ #debug }} |{{ remainingdays }}| {{/}} 

@Vishal Biyani 

Mohamed Eid February 12, 2025

@Vishal Biyani I removed the spaces and it accepted it as below :

 

{{#debug}}|{{remainingdays}}|{{/}}

 

Debug message
|44.9999|
Log
|44.9999|
Then tried the forumaly again as : startdate with asNumber = {{ startdate.toDate("yyyy-MM-dd") }} and remaining days = {{remainingdays.asNumber}}
and it gave me this 
Log
startdate with asNumber = 2025-01-18T00:00:00.0+0100 and remaining days =
then tried without asNumber and it gave me the number(i believe as a string)
startdate without asnumber = {{ startdate.toDate("yyyy-MM-dd") }} and remaining days = {{remainingdays}}
startdate without asnumber = 2025-01-18T00:00:00.0+0100 and remaining days = 44.9999
Then tried the addition and it didnt work both ways as :
startdate with asNumber = {{ startdate.toDate("yyyy-MM-dd") }} and remaining days = {{remainingdays.asNumber}}
Log
startdate with asNumber = 2025-01-18T00:00:00.0+0100 and remaining days =
and also tried {{#debug}} {{ startdate.toDate("yyyy-MM-dd").plusDays(remainingdays)}} {{/}}
Log
Vishal Biyani
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 12, 2025

Thanks for the details. This is great progress you have made.

The issue is at least isolated.

 

Let me think through more what else could be the issue and will respond back tomorrow morning 

Vishal Biyani
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 12, 2025

@Mohamed Eid 

Can you try below steps?

  1. Disable the rule. Then enable it after 10 mins. See if works
  2. If not, create a new rule and have a manual trigger and add the logic to create the smart variable remainingdays then print it lin og remaining days = {{remainingdays.asNumber}}. If it works in the new automation rule, then copy over the remaining logic in this new rule
  3. if #2 does not work, then in your jira instance asNumber is not supported. As you are on cloud this shouldn't be the case. But check the endpoint to be doubly sure https://<your-domain>.atlassian.net/rest/api/3/serverInfo. if this is a case unfortunately, we have hit a dead end. Then the best option will be to have your admin open a ticket against Atlassian

Fingers crossed, either of 1 or 2 should work.

 

Mohamed Eid February 13, 2025

Thanks a lot for your help so far @Vishal Biyani 

I have tried both 1 & 2 and unfortunately they didnt work as below :

Log action

Log
remaining days = 44.9999

Log action

Log
remaining days as number =
and for 3 I am still not sure how to find this piece of info if the endpoint is supported or not yet in out instance
 "version": "1001.0.0-SNAPSHOT",
  "versionNumbers": [1001, 0, 0],
  "deploymentType": "Cloud",
  "buildNumber": 100281,
  "buildDate": "2025-02-12T15:10:38.000+0100",
  "scmInfo": "f9a92c958576393f68d02ead86923e3d1fcf3671",
  "serverTitle": "Jira",
Vishal Biyani
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 13, 2025

@Mohamed Eid 

Your 3rd response confirms you are on Cloud.

Since we have debugged and confirmed that asNumber is not working in your instance, in my opinion you should raise a case with Atlassian and seek their opinion.

if you have paid subscription then your JIRA admin can raise the case.

if you are on free tier, we may have to seek help of a community leader to raise the case on your behalf.

Suggest an answer

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

Atlassian Community Events