nested smart values issue

Anna May 13, 2024

Hi there,

I have checked many posts here and seems to write my smart value correct however, output is blank.

My first variable: {{vicDay}} is defined as

{{now.format("YYYY")}}-05-25

My second variable: {{vicDateDay}} is defined as

{{vicDay.toDate.DayOfWeek.minus(1)}}

Both variables return values in the log: as 2024-05-25 and 4 respectively

Now, I use the numeric value in my third variable: {{vicDayFinal}} defined as

{{vicDay.toDate.minusDays(vicDateDay)}}.

When I type in numeric value in the formula {{vicDay.toDate.minusDays(4)}} it returns 2024-05-20 as expected, when I use vicDateDay variable name then it returns null. The log shows that vicDateDay is Numeric.

Here is the log:

vicDay - 2024-05-25, vicDateDay - 4, vicDayFinal - , isNumeric - true, isAlpha - false

 

Anybody please help me on this.

 

Thanking in advance.

1 answer

1 accepted

1 vote
Answer accepted
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.
May 13, 2024

Hi @Anna 

What problem are you trying to solve by doing this?  Knowing that may help the community to offer alternative solutions.

Until we know that...

Created Variables are text.  When you want to use them in a function such as minusDays() they must be converted with asNumber:

{{vicDay.toDate.minusDays(vicDateDay.asNumber)}}

Kind regards,
Bill

Anna May 14, 2024

Hi Bill, I calculate Victoria Date as a variable. I tried asNumber function and the output is still null. Log is below

Log action

Log
vicDay - 2024-05-25

Log action

Log
vicDateDay - 4

Log action

Log
vicDay.toDate.minusDays(vicDateDay.asNumber)-

I need to exclude my scheduled trigger run on holidays, this is the objective of exercise.

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.
May 14, 2024

Please post an image of your complete rule (in one image) and an image of the audit log details showing the rule execution.  Those will provide context to help explain what you are observing.  Thanks!

Anna May 14, 2024

Bill, please find attached rule with detailstrigger flow.pngvariables and log.png

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.
May 14, 2024

Where you write the smart value expressions to the audit log, try writing the variables instead: {{vicDay}}, {{vicDateDay}}, and {{vicDayFinal}}

That will help confirm the variables contain what you expect.

 

Also, smart values are case-sensitive, and I believe the attribute DayOfWeek should be dayOfWeek: https://confluence.atlassian.com/automation/jira-smart-values-date-and-time-993924864.html#Jirasmartvaluesdateandtime-attributesAttributes

Anna May 14, 2024

hi Bill, thanks a lot for your reply. I have fixed the case to dayOfWeek and always check each calculation in log when move to the next step. I added variable where argument is explicitly defined as number and it works:

{{vicDay.toDate.minusDays(vicDateDay.asNumber)}} - returns null

{{vicDay.toDate.minusDays(4)}} - returns 2024-05-20 as expected

so the issue is caused by variable argument. 

Action details:

Log action

Log
vicDay - 2024-05-25

Log action

Log
vicDateDay - 4

Log action

Log
vicDayFinalWithVariable - , vicDayFinalWithNumberArgument - 2024-05-20
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.
May 14, 2024

I wonder...please try setting vicDateDay to 4 explicitly with no calculation.

If that does not work, it suggests that the minusDays() function for Jira Data Center cannot take a variable as a parameter.  I looked and did not find this listed as a defect in the public backlog

 

A longer version to try would be putting it all together for final date:

{{vicDay.toDate.minusDays(vicDay.toDate.dayOfWeek.minus(1))}}

 

Or, brute force the value with another variable using a math expression, and then convert that to a date:

{{now.format("YYYY")}}-05-{{vicDateDay.asNumber.multiply(-1).plus(25).format("##")}}

 How that works:

  • put the year and month at front
  • convert your vicDateDay value to a number
  • multiplying that by -1 and adding it to 25 (to essentially reorder the math)
  • and format the result

 

Anna May 14, 2024

Bill, explicit argument as number in minusDays() works. I will try the rest of your suggestions and will get back to you

Anna May 14, 2024

Hooray! it worked

Bill, thanks a lot for your great suggestion, i used the line below as you suggested and it worked. I can't believe it, spent 2 days on it with hundreds of combinations!!!

{{vicDay.toDate.minusDays(vicDay.toDate.dayOfWeek.minus(1)).jiraDate}}.

I will mark this as answered

Like Bill Sheboy likes this
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.
May 14, 2024

Awesome; I am glad you have it working!

There are other open defects for Jira Data Center's use of created variables in functions, but not this specific case with minusDays().  You may want to ask your Jira Site Admin to submit a defect so Atlassian knows about it.

Suggest an answer

Log in or Sign up to answer