plusdays function not working when I pass in a variable

JJ
Contributor
October 7, 2020

 

So if I use the function below and hardcode a number, it works. But if I pass in a variable, it does not work. 

Does plusdays not accept variables? If it does, what am I doing wrong?

{{triggerissue.duedate.plusdays({{triggerissue.recurrent days}})}}

 

recurrentdays.gif

4 answers

1 accepted

5 votes
Answer accepted
JJ
Contributor
June 4, 2021

I couldn't accept MA's answer because it was a comment under an existing answer so I'm reposting it here:

I found a key piece of information today that has resolved the calculation of the plusDays and plusBusinessDays function whilst passing in a variable.  Apparently there's an "old" syntax you can use.  Rather than {{issues.field.plusBusinessDays(yourVariable|numeric field)}} you can use the following:

{{#issue.field}}func=plusBusinessDays({{yourVariable|numeric field}}){{/}}

Notes:
replace field in issue.field with the date field in Jira that you want to add days to.
replace yourVariable|numeric field with either a smart value variable or a field storing a number

using this syntax worked for me!

source of information/inspiration was found here - https://codebarrel.atlassian.net/browse/AUT-1791

Nicolas Degardin
Contributor
September 28, 2021

You saved my day!

MA
Contributor
October 4, 2021

Glad this sorted it out for you!

Like Nicolas Degardin likes this
Vinod Kotiya
Contributor
June 9, 2023

Amazing it worked like a charm to increase due date by a variable. Wasted a lot of time for simple issues. JIRA smart value sucks.

{{#issue.dueDate}}func=plusBusinessDays({{varDay}}) {{/}}

Like # people like this
Tecnofor November 21, 2023

Thank you!! You saved my day too!!

Like # people like this
MA
Contributor
November 21, 2023

Happy to have helped :)

Aditya Verma
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 20, 2024

This solution was amazing, I wonder why it is not included in Atlassian's documentation. Thanks @MA  & @JJ .

Like MA likes this
MA
Contributor
April 21, 2024

Glad it helped @Aditya Verma 

Like Jennifer Roth likes this
Tom Hudgins
Contributor
August 20, 2024

It's a crime that we have to resort to this hack - but thank you for posting it.

2 votes
Leonardo Oliveira September 27, 2024

Hey, I found a simpler solution that worked for me. Make sure the variable is a number before performing the operation:

 

{{triggerissue.duedate.plusdays({{variable.asNumber}})}}

 

Mariano Tallarico _Appricity_ November 6, 2024

Hello dear Community! Yup, my joy is the result of the contribution that @Leonardo Oliveira made, which solved a section of my automation process.

I simply wanted to add a resource that worked in my case.

The effective smartvalue ended up being:

{{issue.Start Date.plusdays(DiferenciaDias.asNumber)}} , where the variable "DiferenciaDias" was correctly invoked as it wasn´t enclosed in "{{}}".

Again, thanks for your contribution Leonardo.

0 votes
JJ
Contributor
October 9, 2020

I read online that that's just the way it is. IIt just does not accept variables.

Marius Kymantas December 8, 2020

Are they planning to add this, I also need this functionality. Maybe you found some workarounds? Thanks

Like MA likes this
MA
Contributor
February 8, 2021

I would like this updated too.  I am struggling to see how you will use this automation if you need to use hard coded values in date.plus[unit] functionality.

JJ
Contributor
February 8, 2021

I had to use the variable in the if clause instead... so if <somenumber> = "weekly" then add 7 days a date field, etc. But that may not work for everyone. They need to fix it.

Like MA likes this
MA
Contributor
February 8, 2021

Thanks @JJ that makes sense, but the scenario that I am looking at requires that I add the values of two fields together and this would give me the number of business days that I need to adjust the date by.  I'm not hopeful it will be resolved quickly as the issue that Atlassian has raised for this has been dormant for a couple of years and is sitting unassigned.  :(

Marius Kymantas
Contributor
February 8, 2021

@JJ  have it working after all. You don't need double curly brackets in argument.

{{issue.Planned start date.plusHours(issue.Duration (hours))}} works perfectly fine in my case. Please try this.

Like # people like this
MA
Contributor
February 11, 2021

@Marius Kymantas - tried your suggestion - thanks.

It didn't work for me.

I don't have exactly the same fields as you do, so I couldn't use duration in my Jira instance, but it looks like that you are essentially passing a numeric that is stored in a field, so I figured that if I removed the curly brackets and passed in a field on the issue that resolves to a numeric to the {{issue,start date.plushours()}} function, I should be in the same ballpark.  The result of this approach is that I didn't get an error, but I also didn't get a result (an empty string I assume, since I am outputing my test results to issue.description)

Also, where did you find the information for using <issue.Duration (hours)>.  I can't find this syntax anywhere in the Jira automation or smart values doco that's available on the web?  I assume this converts the duration value (probably stored in seconds) to hours.  All the other objects/fields seem to use a syntax along the lines of issues.duration.hours.  e.g. https://support.atlassian.com/jira-software-cloud/docs/use-smart-values-to-manipulate-and-format-dates/

Marius Kymantas
Contributor
February 11, 2021

@MA "Duration (hours)" is just  custom Jira field name I created (type "number"). I wanted the field name to indicate that people would understand that this number is treated as hour in automation. 

MA
Contributor
February 14, 2021

@Marius Kymantas  Well didn't I just read too much into it then :)

Thanks for the clarification

I guess I have found the automation and smart value documentation a little brief to date, and most of the bits that I have worked out have been by a process of elimination.

I have seen that there has been a request to Atlassian for more comprehensive documentation along the lines of standard functional or language APIs that detail descriptions, types, values, functions and more diverse and robust examples etc.  I'd like to add my voice to this request.

 

MA
Contributor
February 14, 2021

I found a key piece of information today that has resolved the calculation of the plusDays and plusBusinessDays function whilst passing in a variable.  Apparently there's an "old" syntax you can use.  Rather than {{issues.field.plusBusinessDays(yourVariable|numeric field)}} you can use the following:

{{#issue.field}}func=plusBusinessDays({{yourVariable|numeric field}}){{/}}

Notes:
replace field in issue.field with the date field in Jira that you want to add days to.
replace yourVariable|numeric field with either a smart value variable or a field storing a number

using this syntax worked for me!

source of information/inspiration was found here - https://codebarrel.atlassian.net/browse/AUT-1791

HTH

Like # people like this
Abdeladim EL AOUMARI June 4, 2021

thanks @MA for the workaround :)

0 votes
Niranjan
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.
October 7, 2020

Hi,

PlusDays function expects a number value I suppose.

What is the output of {{triggerissue.recurrent days}} ? If that gets a number value, try 

{{triggerissue.duedate.plusDays({{triggerissue.recurrent days}})}} or

 

{{triggerissue.duedate.plusDays({{issue.customfieldId}})}} where customfieldId is the field id of triggerissue.recurrent days

JJ
Contributor
October 7, 2020

The outcome of triggerissue.recurrent days is a double. So that's definitely working.

Suggest an answer

Log in or Sign up to answer