Looping of maximum epic date and assign to initiative in jira automation
Asked by Dwaipayan Dey:

Hello,

I have a project that has multiple initiatives (INT-1, INT-2 etc) associated. Under each initiative there is two or more epics. As an example:

INT-1 has EPIC-1 and EPIC 2

INT-2 has EPIC-3 and EPIC 4

Using automation I am trying to get the maximum actual end date of epics under initiatives and automatically assign it to "baseline date" field of each initiatives.

As an example -

Maximum Actual end date of of Epic 1 and 2 will be assigned as baseline date of INT-1.

Maximum Actual end date of of Epic 3 and 4 will be assigned as baseline date of INT-2.

and the loop goes on till there is end of initiatives.

Any support will be helpful.

![Automation.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/228089i4FF16F5E41FE48FB/image-size/large?v=v2&px=999 "Automation.JPG")


Answers:
author: Bill Sheboy
body: Hi [@Dwaipayan Dey](/t5/user/viewprofilepage/user-id/5090209) -- Welcome to the Atlassian Community!

There are a few things to check for your rule, as you have shown it...

When you note the field "actual end" is that a custom field you added, or do you mean another field? Whatever your field is, please use this how-to article to learn if your field is supported by automation rules, and what the exact smart value name is: <https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/>

Next, you do not show the JQL for your rule, and I suspect it has a problem. Let's clarify a bit...how are you trying to run this rule: triggered based on the Initiatives or something else?

If it is based on the initiatives, then:

* The JQL for the trigger should only include initiatives
* And the lookup issues action should use JQL to find the related epics with the same Initiative as parent. Then the check on the max date will work as you expect.
* And finally the branch to parent would not be needed, as each Initiative from the trigger is processed, it can be edited

Kind regards,  
Bill

comments: author: Dwaipayan Dey
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) , Thanks for your prompt reply.

Regarding your questions -

1. "Actual End" is a custom field added which can show only dates.

2. Trigger for this is - weekly scheduled run (Once in a week) or a manual run.

To Simplify here is the flow -

Scheduled Run/Manual Run -\> search for initiatives -\> search for epics under each initiatives -\> group epics under each initiative -\> get the max date (custom field - actual end date) from epics and apply it to "baseline date" (Custom field of initiative) of parent initiative -\> Loop the process till all initiatives are updated with correct baseline dates.


author: Bill Sheboy
body: Thanks for that information.

If your scheduled trigger is indeed using JQL to only find the Initiatives, using the Lookup Issues on the epics for each Initiative should work. As are reminder, the branch to parent is not needed.

**What is not happening as you expect**, as your rule could be:

* trigger: scheduled on JQL to gather the initiatives
* action: lookup issues on JQL to get the epics for the current initiative
* advanced compare condition: to check there were any lookup results
  * first value: {{lookupIssues.size\|0}}
  * condition: greater than
  * second value: 0
* action: edit the initiative to set the date to the maximum from the lookup


Tags: smart-value