Forums

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

JIRA (Data Center) automation - Problem with calculations with values from the changelog

Patrick Schmidt January 17, 2024

Hi there,

I'm trying to run a date comparison from two values pulled from the changelog by smart values.

{{changelog.Target end.from}} - Output: 2024-11-15

{{changelog.Target end.to}} - Output: 2024-11-13

I suppose that I will need to convert the output to a date format to do some maths...

{{changelog.Target end.from.toDate("yyyy-MM-dd")}}

...returns something but not the output, which I expected:

Output:  Fri Nov 15 00:00:00 CET 2024

First question - Why is that the case?

Second question - Is there a way to do some maths with diff to compare both smart values? Everything I'm trying results in an empty output.

 

Thanks a lot,

Patrick

 

 

 

1 answer

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.
January 17, 2024

Hi @Patrick Schmidt 

First thing, I am using Jira Cloud and not the Server version (which your post seems to indicate).  Please test with your version for the things I am suggesting.  Thanks!

When you added the format string of "yyyy-MM-dd" to the toDate() function that helped with the conversion, and the resulting date / time value appears to be returning in whatever your system and profile are using for date / time formats.

Next, the diff() should be possible if all of the values are actually valid date / times.  Would you please show your complete rule, and the specifics of where you are performing the diff?  And show the audit log details for the rule execution.  Those will provide context to help explain what you are observing.

Kind regards,
Bill

Patrick Schmidt January 18, 2024

Hi @Bill Sheboy

thanks for taking this up again.

The time format is only specified global. I can't find anything set in addition in my profile.

Date-JIRA-config.JPG

Here's the rule and all the steps to set variables, mail config and mail output:

date-rule.JPG

date-variable-oldtarget.JPG

date-variable-newtarget.JPG

date-diff.JPG

date-mail.JPG

date-output.JPG

Thanks,

Patrick

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.
January 18, 2024

When you create a variable, that is stored as a text value.  Those variables need to be converted to date before using the diff() function.

In your create of the "Diff" variable, that would be this, adding the missing units of measure, days:

{{OldTargetEnd.toDate.diff(NewTargetEnd.toDate).days}}

 

One more thing: when creating variables, I suggest adding a prefix to ensure the name is always unique and will not collide with other fields or rule features.  For example, consider renaming that variable from Diff to varDiff by adding a prefix of var to symbolize it is a variable.

Patrick Schmidt January 18, 2024

Hi @Bill Sheboy

I've got no luck with the new diff variable

{{OldTargetEnd.toDate.diff(NewTargetEnd.toDate)}} doesn't work, neither does

{{#=}}{{OldTargetEnd.toDate.diff(NewTargetEnd.toDate)}}{{/}}

Both result in an empty output and the audit log has no errors.

Same with...

{{OldTargetEnd.toDate("yyyy-MM-dd").diff(NewTargetEnd.toDate("yyyy-MM-dd"))}}

{{#=}}{{OldTargetEnd.toDate("yyyy-MM-dd").diff(NewTargetEnd.toDate("yyyy-MM-dd"))}}{{/}}

 

Thanks and have a nice weekend,

Patrick

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.
January 20, 2024

I wonder if the variables with the converted values are still in a format which cannot be directly converted with toDate.

Please try writing the variable to the audit log to confirm the format, and perhaps add more conversion with toDate.

Patrick Schmidt January 22, 2024

Hi @Bill Sheboy

I'm afraid I'll need some support with that. My audit log doesn't say much. Didn't find a way to write something to the audit log yet.

Thanks a lot,

Patrick

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.
January 22, 2024

There is a rule Log action which allows writing any value to the audit log when the rule executes:

https://confluence.atlassian.com/automation/jira-automation-actions-993924834.html#Jiraautomationactions-logactionLogaction

Writing the variable to the log will help identify what is happening.

Patrick Schmidt January 24, 2024

Hi @Bill Sheboy

thanks for the hint. Unfortunately the audit log also shows an empty variable.

Thanks,

Patrick

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.
January 24, 2024

Please show images of:

  • action details to create your variable
  • audit log details showing the rule run writing out that variable
Patrick Schmidt January 28, 2024

Hi  @Bill Sheboy

sorry I must have missed your reply. Here are the images:

variable.JPGvariable_to_log.JPGlog.JPG

Thanks,

Patrick

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.
January 29, 2024

Thanks for that additional information!

FYI: I recommend adding a prefix to variable names for rules and not using anything similar to built-in functions and features, such as "Diff".  That will avoid errors / confusion from any typos.  For example, perhaps name that variable varDiff.

 

Also, please add writes to the audit log of the converted, variable values:

  • OldTargetEnd converted to date: {{OldTargetEnd.toDate("yyyy-MM-dd")}}
  • NewTargetEnd converted to date: {{NewTargetEnd.toDate("yyyy-MM-dd")}}

Those will confirm the conversions work prior to use in the diff() function.  Then re-test your rule.

 

Finally, would you please post an image of your complete rule?  That may provide some context to explain why the value is null.

Patrick Schmidt January 29, 2024

Hi @Bill Sheboy

here's the audit log with the new entries:

log2.JPG

...and the rule. The definition of the variables can already be found above:

 

date-rule2.JPG

Thanks,

Patrick

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.
January 29, 2024

This is quite odd...

Let's try in-lining the entire expression and writing that to the log:

{{changelog.Target end.from.toDate("yyyy-MM-dd").diff(changelog.Target end.to.toDate("yyyy-MM-dd")).days}}

And...I noted some of your diff() function calls are missing the units of measure at the end.  Please look to see if your varDiff one is missing the units when the variable is created.

Patrick Schmidt January 31, 2024

Hi @Bill Sheboy

unfortunately that didn't help either...

variable2.JPGlog3.JPG

Thanks,

Patrick

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.
January 31, 2024

Well, I am out of suggestions.  If your rule is matching what the log shows the dates are converting, but only sometimes.

At this point I recommend working with your site admin to contact Atlassian Support: https://support.atlassian.com/contact/#/

After you hear back from them, please post what you learn to benefit the community.  Thanks!

Patrick Schmidt January 31, 2024

Thanks @Bill Sheboy

will post the solution here in case I get one.

 

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer