I have a question regarding increasing the due date of an issue by adding a comment with a specific phrase.
My goal was when a comment is written and the expression +2w or +2W is used, the due date of the task is moved forward by 2 weeks. Specifically, to the Tuesday two weeks from now.
Initially, I hardcoded it with the following code:
{{now.withNextDayOfWeek("TUE").plusWeeks(2)}}
However, I then had the idea to make it dynamic. In other words, even if +6w or +200w is used, the number between the plus sign (+) and the w should be used for the calculation.
Extracting and storing the value in a variable wasn't a problem. However, using that variable within the code mentioned earlier simply didn't work as expected.
To store the value in a variable, I did the following:
Action: Create Variable
Name: numberOfWeeksToBeMoved
Smart-Value: {{comment.body.match("\+(\d{1,3})[wW]")}}
Next, I used the function mentioned above and simply replaced the 2 with my variable.
{{now.withNextDayOfWeek("TUE").plusWeeks({{numberOfWeeksToBeMoved}})}}
While testing the function, I received the following error:
Error rendering smart-values when executing this rule:
Failed to get value for now.withNextDayOfWeek("TUE").plusWeeks({{numberOfWeeksToBeMoved: {{now.withNextDayOfWeek("TUE").plusWeeks({{numberOfWeeksToBeMoved}})}}
While researching, I came across tips suggesting that the issue might be due to the variable not being a number. I tested this using numberOfWeeksToBeMoved.isNumeric, and it returned true as the result.
Therefore, I couldn't imagine that this was the problem.
Especially, I also tested calling my variable with numberOfWeeksToBeMoved.asNumber. Also without success.
Later, I found another method:
{{#now}}func=plusWeeks({{numberOfWeeksToBeMoved}}){{/}}
This method at least worked in the sense that my variable was used in the addition function, and "Today" was calculated in x weeks.
That in turn proves that my variable is recognized as a number.
Now I wanted to somehow incorporate Tuesday, but I simply didn't get the results I wanted.
Test 1
{{#now}}func=plusWeeks({{numberOfWeeksToBeMoved}}).withNextDayOfWeek("TUE"){{/}}
Result: Today in X weeks, without considering Tuesday.
Test 2
{{#now.withNextDayOfWeek("TUE")}}func=plusWeeks({{numberOfWeeksToBeMoved}}){{/}}
Result: String output "func=plusWeeks(3)"
The number to be calculated was correctly extracted, but the function could not be executed correctly.
No matter how I twisted and tried, nothing worked.
Ultimately, I was able to solve the problem myself, but I wonder if there is a simpler or better way.
My knowledge of Smart-Values is limited, but I couldn't imagine it would be theoretically so complex, especially since there's such a simple function for it.
Maybe I'm just overlooking something. Perhaps there's someone else who has tried and implemented something similar.
Here's my workaround
Trigger: When Issue commented
Condition: If Compare two values
First value: {{comment.body}}
Condition: contains regular expression
Regular expression: \+(\d{1,3})[wW]
Action 1: Create variable
Variable name: currentDuedate
Smart Value: {{duedate}}
Action 2: Create variable
Variable name: numberOfWeeksToBeMoved
Smart Value: {{comment.body.match("\+(\d{1,3})[wW]")}}
Action 3: Create variable
Variable name: tuesdayOfNextWeek
Smart Value: {{now.withNextDayOfWeek("TUE")}}
Action 4: Create variable
Variable name: tuesdayInFewWeeks
Smart Value: {{#tuesdayOfNextWeek.ToDate}}func=plusWeeks({{numberOfWeeksToBeMoved}}){{/}}
Action 5: Create variable
Variable name: newDuedate
Smart Value: {{#tuesdayInFewWeeks.ToDate}}func=minusWeeks(1){{/}}
(The calculation with minus one week is necessary because we are counting from next Tuesday plus x weeks.)
Action 6: Edit issue fields
Field: Due Date
Value: {{newDuedate}}
Action 7: Add value to the audit Log
Field: Due Date
Value: {{newDuedate}}
Have a nice day,
Martin