Heads up! On March 5, starting at 4:30 PM Central Time, our community will be undergoing scheduled maintenance for a few hours. During this time, you might find the site temporarily inaccessible. Thanks for your patience. Read more.
×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:
Hello @Chaya
Try removing the curly braces that you have around days in your JSON code, such that it becomes
...plusBusinessDays(days)...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Trudy 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Trudy 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Perhaps there is a typo within your rule. Perhaps the field is not the Date Picker field type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Trudy 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have found the solution documented in another post
{
"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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Trudy 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Trudy 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}}" } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're welcome!
It took a while, but the journey was educational.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.