The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Jira automation to set Target End using smart value variable

Chaya
August 28, 2024

I am trying to set Target End using jira automation based on the value of Story Points(1 story point = 1 business day).

So I am creating a smart value variable named days as below:

{{#=}}CEILING({{issue.Story Points}} + 1){{/}}

Then I am trying to set Target Date using JSON Object. When I dont use days variable, just passing number to plusBusinessDays function is working. But when I try to use days variable, it is not working.

My Automation rule looks like below:

Capture.PNG

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Trudy P Claspill
Community Champion
August 28, 2024

Hello @Chaya 

Try removing the curly braces that you have around days in your JSON code, such that it becomes

...plusBusinessDays(days)...

Chaya
August 28, 2024

@Trudy P Claspill  I tried that, it is not working. It is giving me Unparseable date: "" error

Trudy P Claspill
Community Champion
August 28, 2024

What type of field is customfield_12344?

Have you used a Log action to confirm that the days variable actually contains a value?

Have you used a Log action to confirm that customfield_12344 contains an valid value?

You can also use Log actions to print out each stage of the construction of the smart value you are trying to use in your JSON.

Chaya
August 28, 2024

@Trudy P Claspill that custom field is Target Start. Yes I tried to log it and it is logging in correctly. Above json object works like a charm when I replace days with actual number (ex. 2,3,etc). I also logged days and it is also giving the right output. 

Trudy P Claspill
Community Champion
August 28, 2024

@Chaya 

Can you tell us the field type for customfield_12344?

The name of the field is not the same thing as the field type. Is the field a Text field? I it a Date/Time field? Is it a Date field?

Using the Log action is a debugging technique you can use to confirm the values you are reading and calculating are what you expect. I don't see any Log actions in your rule steps. Please add those actions back into your rule, run the rule again, and then  share with us the output from the rule execution log file. Also share with us the details of each Log action so that we know what you are trying to print into the log. That will help us help you debug the rule. 

Without that information, we are offering only educated guesses about how your rule needs to be fixed.

If I knew for a fact the field type for your custom field I could advise you about whether the smart value you are trying to use in the JSON code is valid.

For instance, if it is a Date or Date/Time field you should not be using the toDate function since it is already the correct field type. Nor should you be using the format() function prior to using the plusBusinessDays function. Instead of

{{issue.fields.customfield_12344.toDate.format(...).plusBusinessDays

you should use

{{issue.fields.customfield_12344.plusBusinessDays

 

Chaya
August 29, 2024

@Trudy P Claspill I tried to log {{issue.fields.customfield_12344}} and got output as 2024-09-04 when I set it to 4-Sept-2024 in Jira. So Target Start is a date field.

Then I tried to log {{issue.fields.customfield_12344.plusBusinessDays(2)}} and log printed nothing. plusBusinessDays does not work with date fields.

Trudy P Claspill
Community Champion
August 29, 2024

I have done my own test on Jira DC 9.4.11. For me the function works correctly when I use it with a custom field of type Date Picker

Screenshot 2024-08-29 at 12.09.07 PM.pngScreenshot 2024-08-29 at 12.10.13 PM.png

Perhaps there is a typo within your rule. Perhaps the field is not the Date Picker field type.

Chaya
August 29, 2024

@Trudy P Claspill Instead of using custom date picker field, could you please try using existing Target Start field in Jira. Add Target Start and Target End jira fields in your issue screens and then try using it.

Trudy P Claspill
Community Champion
August 29, 2024

Ah ha! Now it is clear to me that I have been misunderstanding part of what you've been saying.

I kept asking what the custom field type was and your answer was "the custom field is Target Start".

I thought you were just repeating the name of the field. I did not realize you were talking about a built in custom field named "Target start" where the field type is also "Target start".

My apologies. I don't work often with Jira DC nor with the Advanced Roadmaps/Portfolio functionality.

Now that I have understood, I corrected my test scenario and can confirm that I get the same result as you - trying to use plusBusinessDays on the Target start field results in nothing printed into the rule execution log.

 

Doing some more research I found examples of setting the Target start field based on data from elsewhere. It appears that you have to reference a date value that has been formatted using jiraDate.

https://confluence.atlassian.com/jirakb/how-to-update-a-story-s-target-start-and-end-dates-based-on-the-sprint-dates-using-jira-automation-1189790988.html

 

This worked to change the value of Target start for me, using the original value of Target start (customfield_13352) as the starting value to calculate the new value:

{
"fields": {"Target start": "{{issue.fields.customfield_13352.toDate.plusBusinessDays(2).jiraDate}}"
}
}

I haven't yet been successful when I replace the "2" with a created variable. I get errors in that case. I'm still experimenting to see if I can solve that.

Like • Chaya likes this
Chaya
August 29, 2024

@Trudy P Claspill yes, you summurized my problem well. 

Trudy P Claspill
Community Champion
August 29, 2024

I have found the solution documented in another post

https://community.atlassian.com/t5/Jira-questions/plusdays-function-not-working-when-I-pass-in-a-variable/qaq-p/1500605

{
"fields": {"Target start": "{{#issue.fields.customfield_13352.toDate}}func=plusBusinessDays({{varDays}}){{/}}"
}
}

In my testing, creating a variable named varDays and where customfield_13352 is the Target start field, this worked for me.

Chaya
August 29, 2024

@Trudy P Claspill Thanks, finally I got it working with the help of your above answer.

For some reason, when I got the Start Date, Jira was giving me Start Date - 1. So I first fixed that. Then for some reason, when I used toDate function, Jira was giving me Date with T17:00:00:00.0-0700. But I wanted date with T00:00:00:00.0-0700 so I used toastartOfDay method. Then I used variables to get the final answer.

Below were my variables:

days - {{#=}}CEILING({{issue.Story Points}}){{/}}

targetStartVar - {{issue.fields.customfield_12344.toDate.toStartOfDay.plusDays(1)}}

targetEndVar - {{#targetStartVar.toDate}}func=plusBusinessDays({{days}}){{/}}

And then finally setting up Target End using JSON object below:

{
"fields": {"Target end": "{{targetEndVar}}"
}
}

Above code worked for me. For some reason, I wasn't able to concatenate targetStartVar and targetEndVar code inside JSON object. With the help of targetStartVar and targetEndVar, I was able to automate Target End date.

 

Chaya
August 29, 2024

@Trudy P Claspill Thanks, this worked for me.

For some reason, when I tried to logging Start Date, Jira was giving me Start Date - 1 and giving me time as T17:00:00:00.0-0700 instead of T00:00:00:00.0-0700. To fix this issue, I used toStartOfDay method. I was unable to use all of this code inside JSON object so I used smart variables.

I have below variables:

days - {{#=}}CEILING({{issue.Story Points}}){{/}}

targetStartVar - {{issue.fields.customfield_12344.toDate.toStartOfDay.plusDays(1)}}

# above line fixed date minus 1 and Time issue

targetEndVar - {{#targetStartVar.toDate}}func=plusBusinessDays({{days}}){{/}}

Then my final JSON object looks like below:

{ "fields": {"Target end": "{{targetEndVar}}" } }

Like • Trudy P Claspill likes this
Trudy P Claspill
Community Champion
August 29, 2024

You're welcome!

It took a while, but the journey was educational.