Weekly sub-tasks scheduled each month
Asked by Mattia Battan:

hello everyone,  
I am trying to create an automation that creates every 1st of the month, sub-tasks of all Wednesdays (for example) of the month where the field ""recurrent re-opening\[Dropdown\]" = Weekly" is selected.  
This creation must depend on a variable date field called "Final Solution Date." (If for example a Monday is entered, the next month must create the sub.tasks of all the Mondays of that month etc.).

Now my problem, by putting in the "final solution date" of my main task on April 12 (which is a Friday for example), I would like it to create on the first day of the next month the sub-tasks of the remaining Fridays, and thus: the 12th, the 19th and the 26th (total 3 sub-tasks).  
If I then change the date and put May 1, it should create 5 of them (being 5 Wednesdays in that month).

How can this be done?

Thanks


Answers:
author: Kalyan Sattaluri
body: Hello [@Mattia Battan](/t5/user/viewprofilepage/user-id/5102968)

I am not understanding the trigger of your requirement..

I gather that based on what "Final Solution date" is entered, you want to create sub-tasks, but What if this field is changed again same month? Wont you end up with multiple sub-tasks everytime? So your requirement is confusing.

But assuming this field change is the trigger and it will be changed only once..

Probably many ways to do this, I guess I am proposing a brute force check.. Looking forward to other options as well...

**My suggestion:**

Below smart values gives you number of wednesdays in a month:

{{#=}}CEILING({{**Final Solution date** .firstOfTheMonth(3).diff(**Final Solution date**.lastOfTheMonth(3)).days}}/7 + 1){{/}}

Where,

* "Final Solution date" is the field, change it / match it accordingly.
* firstOfTheMonth(3) gives the date of the first wednesday,
* lastOfTheMonth(3) gives the last wednesday,
* We do a difference, divide by 7 and add +1 to include all occurrences.
* and CEILING will round up to the nearest integer incase the date time stamp diff does not give a whole number.

Again, assuming your trigger is field change to "Final Solution date" field. You can do a refetch action after the trigger and then do the If/Else condition check and create sub-tasks accordingly.

Now, We know a month can only have either 4 or 5 wednesdays, So before you start creating sub-tasks, put an if/else condition -\> smart value condition and check if above smart value equals 4, if so create 4 sub-tasks, else create 5.

Like below screenshot: (Its a DC screenshot but cloud has similar logic)

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/315336iE32857BA5B473B43/image-size/large?v=v2&px=999 "image.png")To test this.. what ever your trigger, use your field, Final Solution date and below smart value for checks:

{{#=}}CEILING({{issue.Final Solution date.firstOfTheMonth(3).diff(issue.Final Solution date.lastOfTheMonth(3)).days}}/7 + 1){{/}}

But dont create sub-tasks yet, just log like I did to make sure you are entering the correct If condition.. Only after verifying that, I suggest you create sub-tasks to avoid unnecessary issues.

comments: author: Mattia Battan
body: hi Kalyan,

my trigger starts once a month, on the first of the month and reads the "final solution date" of the main task, and having set for example April 3, I would like only 4 subtasks to be created with the final solution dates:  
- April 3  
- April 10  
- April 17  
- April 24

Leaving April 3 as the main task, I would like 5 subtasks to be created on May 1:  
- May 1  
- May 8  
- May 15  
- May 22  
- May 29

On the other hand, if at any time the "final solution date" of the main task is changed, from the next first of the month, it will have to create the number of subtasks in relation to that day.  
I think the only thing I am missing is to add an "if" that does this check.

Thanks

![2024-04-02 08_43_42-Clipboard.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/315659iF8E88532B478FC9B/image-size/large?v=v2&px=999 "2024-04-02 08_43_42-Clipboard.jpg")


author: Mattia Battan
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) I tried your rule and it works when the Wednesday of the month selected in the "final solution date" has 4 or 5 weeks.  
How can I make it variable, i.e. your "if" doesn't read only if Wednesday has 4 or 5 weeks, but any day?  
thanks again


author: Kalyan Sattaluri
body: Hello [@Mattia Battan](/t5/user/viewprofilepage/user-id/5102968)

Hmm. I am not sure what do you mean by "variable"? Where will this variable come from? user input? or derived from the date in your field? I personally think you are complicating this. I honestly dont know how to do that without extensive If/Else statements... There maybe simpler approach I am missing.

My suggestion is to please take a moment to understand/document what do you want / requirement.

Then please post a new question / thread so community can help.

In the mean time, if the original ask of this post is clarified, please consider accepting the answer so others can benefit. Thanks!


author: Mattia Battan
body: hi [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) ,

I confirm that your formula works, I actually had to add some "if", also I had to create 4 separate automations (there is a limit of 65 steps per single automation). For example if the month has 4 days and the "final solution date" was a Monday I did as in the screenshot, then there is an "if" for each day of the week.

Thanks

![2024-04-02 08_43_42-Clipboard.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/315774i64A03D2FDA3A1E13/image-size/large?v=v2&px=999 "2024-04-02 08_43_42-Clipboard.jpg")


author: Ste Wright
body: Hi [@Mattia Battan](/t5/user/viewprofilepage/user-id/5102968)

Can you clarify the logic for us here?

* Automation creates a new task on the 1st of each month
* The "Final Solution Date" is populated on this parent task
* Whatever day that field falls upon, there should then be a sub-task created based on every other same day that exists within that month

...is this correct?

comments: author: Mattia Battan
body: hello Stephen,  
Let me explain further:  
- The manager of our finance department has main tasks and must have a number of precise sub-tasks regarding the current month  
- every 1st of the month automation is triggered, which reads the "Final Solution date" field (which can change from month to month) and creates sub-tasks  
- for example setting May 1 (a Wednesday), it should create 5 subtasks (because May has 5 Wednesdays)  
- however, if he sets June 5 (a Wednesday), he should create 4, because there are 4 Wednesdays in June.

So it should be from month to month variable based on the change of the "Final Solution Date" of the main task.

At the moment I made a rule that creates 5 sub-tasks regardless, but this doesn't work for me, because for example with May it worked correctly, but with April it didn't (it created an extra sub-task with "final solution date" May 3 and this was supposed to be created the next month:![2024-03-29 10_21_22-Rule builder - Automation - Accounting and Finance - Jira.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/315296i00150AD7EE146D0E/image-size/large?v=v2&px=999 "2024-03-29 10_21_22-Rule builder - Automation - Accounting and Finance - Jira.jpg")

![2024-03-29 10_21_36-List - Accounting and Finance - Jira.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/315297iDBE64F63EAC265BE/image-size/large?v=v2&px=999 "2024-03-29 10_21_36-List - Accounting and Finance - Jira.jpg")![2024-03-29 10_24_20-List - Accounting and Finance - Jira.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/315299iC092A107DEF55B1D/image-size/large?v=v2&px=999 "2024-03-29 10_24_20-List - Accounting and Finance - Jira.jpg")

Thanks