Updating calculated number field using automation

Lana Decker April 19, 2023

I need to calculate how many days it was since the risk became actualized Issue.

when Risk becomes the Issue, we set the date "Issue Date"

I need to calculate the number of days between that date and today - and record it in "Days in" scripted field.

I tried to use Edit Issue action and set this field using this script:

{
"fields": {
"Days in": { "value": {{issue.customfield_10803.diff(issue.customfield_10820).days}}
}
}

No bueno! what am I doing wrong?

3 answers

0 votes
Lana Decker April 20, 2023

Made following changes:
change 1.jpg

Result looks like this:

Result 2.jpg

Checking "successful" issues - still empty customfield_10821 (which is a NUMBER field).

 

(Thank you for your help, Florian)

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 19, 2023

Hi @Lana Decker 

Would you please post images of your complete rule and the audit log details showing the rule execution?  Those may provide some context for what you are observing, and give the community ideas on what to suggest.  Thanks!

Until we see that...

This could be a scoping problem, based on where you are performing that date diff() in the rule.  It could also be a timing problem, if the issue you are using was just created.

Kind regards,
Bill

Lana Decker April 20, 2023

I posted a few  - answering questions from Florian, making changes per his suggestions. 

To address your points:

This could be a scoping problem, based on where you are performing that date diff() in the rule.  - I am trying to set a number field from EDIT action , triggered on schedule (see screenshots). 

It could also be a timing problem, if the issue you are using was just created. - no, most tickets are over a week old or older, only one is new.

0 votes
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 19, 2023

Hi @Lana Decker 

Have you try to use the smart value below ?

 

{{now.diff(issue.created).days}}

 

Do not use the advancedediting but select the filed in the list and populate the field with the value above.

 

Reagrds

Lana Decker April 19, 2023

Thank you for your suggestion! 


Days in is a scripted field type and its not selectable - so I created another field (number type)

Using {{now.diff(issueID=10821).days}} - I would expect to get number between date field 10821 and today in days - but get no errors, no result

Using {{now.diff(issue.created).days}} - I would expect to get number between that date and today in days - but get no errors, no result.

 

Automation says success, but the field is empty. 

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 20, 2023

{{now.diff(issueID=10821).days}}  is not valid you should use

{{now.diff(issue.customfield_10821).days}} 

 

When you say no result, is that there is nothing displayed or the field is empty when you try to edit it ? Is the field on the view screen ?

 

Regards

Lana Decker April 20, 2023

Field is on all screens (or a single screen we use for create, edit and view).

I edited query per your suggestion and get this when rule is triggered manually:

result.jpg

Checking any of the "successfully edited" issues i see that field is null in all of them.

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 20, 2023

I would say that the field with id 10821 do not have context for the porject you are trying to apply the automation on.

Can you share the automation definition as well ?

Lana Decker April 20, 2023

If it didn't exist I would not be able to set it manually - but I can (also it wouldn't appear on the screen in the first place).

Rule scope is All projects. 

I tried to run it as me (god admin) and service god admin account with same result.

Rule.jpg

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 20, 2023

Can you add an action "Log action" before the edit and copy paste what you have in the Days as Issue, {{now...... ?

 

So you will be able to see in the audit log of the value return by the smartvalue to see if it's what is expected.

What is the type of the field with id 10821 ?

Also you can update the JQL with something like Key = ISSUe_KEY in the test phase to try it on 1 issue instead of 500 or more.

 

Regards

Lana Decker April 20, 2023

change 1.jpg

result:

Result 2.jpg

Checking "successful" issues - still empty customfield_10821 (which is a NUMBER field).

Lana Decker April 20, 2023

Targeting specific issue: 

Result 3.jpg

issue history , activity has no changes - and field is still empty, but editable manually.

Sebastian Mondry
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 27, 2023

Hi @Lana Decker

This is quite unusual, as I can't see anything wrong with your rule. 

Screenshot 2023-04-28 at 3.52.39 pm.png

Tried replicating something similar, whereby I have a schedule rule which uses JQL to search for a single issue, I then Log out {{now.diff(issue.created).days}} and as you can see, get the desired value of -63.

Would you mind reaching out to the Atlassian support team https://getsupport.atlassian.com/ ? They can look at your instance and understand what's going wrong. 

Thanks !

Suggest an answer

Log in or Sign up to answer