Automation rule results only shown after hitting the refresh button

Mouna Hammoudi October 24, 2023

I am using 2 automation rules for producing sub features for Jira data center when the user clicks on a given transition. enter image description here

The first automation rule is reponsible for giving me a summary about the actions that will be executed. Here is my first automation rule: enter image description here

Here is the code for the first automation rule:

package SuperFeature
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

    
def log = Logger.getLogger('atlassian-jira.log')
List < String > componentList = new ArrayList < String > ()
def projectNames = [ 'WF', 'BF', 'EF', 'YF', 'CLTF']
log.warn("=====MOUNA CAMELIA ISSUE 1:::: "+ issue )

log.warn("=====MOUNA CAMELIA ISSUE:::: "+ issue +" ISSUE COMPONENTS "+issue.getComponents())
if (issue.getComponents().size() == 0) {
    issue.update {
         String text = "Issue does not have any components\n"

        setCustomFieldValue('Execution Summary', text )
    }
} else if (issue.getFixVersions().size() == 0) {
    issue.update {
        String text = "Issue does not have any fix versions\n"
        setCustomFieldValue('Execution Summary', text)
    }
} else {
    int componentSize = issue.getComponents().size()
   
    int generatedIssuesCounter= 0
     for (ProjectComponent component: issue.getComponents()) {
                      String componentName = component.getName()
                    def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)
                    def projectName = componentName.substring(0, componentName.indexOf("-"))
                
                        

                        if(projectNames.contains(projectName)){

                        
                        
                        def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)

                        //log.warn("MOUNA CAMELIA found--"+found+"--NEW LIST SIZE: "+newList)
                        List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents());
                        def found = newList.any {
                            it.getName().equals(shortenedComponentName)
                        }
                        if (found) {
                            componentList.add(componentName+" ===> WILL BE GENERATED")
                            generatedIssuesCounter++
                        } else{
                            componentList.add(componentName+" ===> CANNOT BE GENERATED")

                        }
                        }
            
     }

     


    issue.update {
        String text = "The super feature " + issue + " will be split into " + generatedIssuesCounter + " features, one for each component:\n"
        
       text = text + componentList.join("\n")    ;
         // Partition a list into list of lists size 3
       

        setCustomFieldValue('Execution Summary', text)
    }
}
    

The second code for my automation rule is responsible for generaring child features depending on the component under question. For example, since we have the componet EF-ADMAF, I would generate a child fetaure that belongs to the project EF and that has the component ADAMF.

Here is the 2nd automation rule: enter image description here

Here is the code for my 2nd automation rule:

package SuperFeature

import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

    
def log = Logger.getLogger('atlassian-jira.log')
List < ProjectComponent > finalComponentList = new ArrayList < ProjectComponent > ()
def projectNames = [ 'WF', 'BF', 'EF', 'YF', 'CLTF']



    int componentSize = issue.getComponents().size()
   
    int generatedIssuesCounter= 0
     for (ProjectComponent component: issue.getComponents()) {
                      String componentName = component.getName()
                    def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)
                    def projectName = componentName.substring(0, componentName.indexOf("-"))
                
                        

                        if(projectNames.contains(projectName)){

                        
                        
                                        def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)

                                        List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents());
                                            def found = newList.any {
                                                it.getName().equals(shortenedComponentName)
                                            }
                                            if (found) {
                                                finalComponentList.add(component)
                                                generatedIssuesCounter++
                                            } 
                        }
            
     }


    createFeature(issue, finalComponentList)

void createFeature(Issue issue, Collection < ProjectComponent > componentList) {
    JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
   

    long issueLinkType = 10070 as long
    long sequence = 1 as long
    long myissueID = issue.getId() as long
    // the key of the project under which the version will get created
    final String projectKey = "SF"
    // the start date - optional
    final Date startDate = null
    // the release date - optional
    final Date releaseDate = null
    // a description for the new version - optional
    final String description = null
    // id of the version to schedule after the given version object - optional
    final Long scheduleAfterVersion = null
    // true if this is a released version
    final boolean released = false
    def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey)
    assert project: "Could not find project with key $projectKey"
    ProjectComponentManager projectComponentManager = ComponentAccessor.getProjectComponentManager()
    for (ProjectComponent component: componentList) {
       
        String componentName = component.getName()
        def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)
        def projectName = componentName.substring(0, componentName.indexOf("-"))
       
        def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)
        log.warn("MOUNA CAMELIA HELLO 7 projectName--" + newIssueproject + "--")
        List < String > newIssueProjectVersionIDs = new ArrayList < String > ()
        newIssueProjectVersionIDs = newIssueproject.getVersions().collect {
            it.getName()
        }
        log.warn("MOUNA CAMELIA HELLO 8 newIssueProjectVersionIDs--" + newIssueProjectVersionIDs + "--")
       
        def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10790"); // here replace the ID with ID of your custom field.
        def value = issue.getCustomFieldValue(customField);
        log.warn("MOUNA CAMELIA HELLO 10 mynewVersions--" + customField + "--")
        
        log.warn("MOUNA CAMELIA 11")
        // log.warn("MOUNA CAMELIA ISSUE FIX VERSIONS " + issue.getFixVersions()[0].getClass())
        // log.warn("MOUNA CAMELIA NEW ISSUE PROJECT VERSIONS " + newIssueproject.getVersions()[0].getClass())
         def matchedVersions = issue.getFixVersions().intersect(newIssueproject.getVersions(), Version.NAME_COMPARATOR)
               log.warn("MOUNA CAMELIA MATCHED VERSIONS " + matchedVersions)

       
        // def customField =  ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10790");// here replace the ID with ID of your custom field.
        //  def value = issue.getCustomFieldValue(customField) ;    
        // newissue.setCustomFieldValue(customField, value)
        log.warn("MOUNA CAMELIA HELLO 6 newIssueproject " + newIssueproject)
        log.warn("MOUNA CAMELIA HELLO 7 component.getDescription() " + component.getDescription())
        log.warn("MOUNA CAMELIA HELLO 8  component.getLead() " + component.getLead())
        log.warn("MOUNA CAMELIA HELLO 9  component.assigneeType() " + component.assigneeType)
        log.warn("MOUNA CAMELIA HELLO 10  component.getProjectId() " + component.getProjectId())
        log.warn("MOUNA CAMELIA HELLO 11--" + shortenedComponentName + "--")
       
        ProjectComponent newComponent = projectComponentManager.findByComponentName(newIssueproject.getId(), shortenedComponentName)
       
     
        def componentArray = new String[1]
        componentArray[0]=newComponent.getName()
       // newissue.setComponent(mynewComponentList)
       // def newIssueCreated = newissue
        log.warn(" MOUNA CAMELIA 2 ==========================")
       
        def versionCreator = ComponentAccessor.versionManager.&createVersion.rcurry(startDate, releaseDate, description, newIssueproject.id, scheduleAfterVersion, released)
        def mynewVersions = issue.fixVersions.intersect(newIssueproject.versions, Version.NAME_COMPARATOR).collect {
            versionCreator it.name + '-Inbox'
        }
        log.warn("MOUNA CAMELIA 12 " + mynewVersions)
     
               // newissue.setFixVersions(mynewVersions)
        Issue newissue = Issues.create(projectName, 'Feature') {
            setSummary("["+shortenedComponentName+"] "+issue.getSummary())
            setDescription("This feature has been generated as child of a super feature. Please use this text area to add child feature specific information.")
            setReporter(issue.getReporter())
            setCustomFieldValue(customField.getFieldName(), value)
            setFixVersions(mynewVersions as String[])
            setComponents (componentArray as String[])
        }
          log.warn("MOUNA CAMELIA 13")



         long newIssueCreatedID = newissue.getId() as long
        def labelManager = ComponentAccessor.getComponent(LabelManager)
        labelManager.addLabel(authenticationContext.getLoggedInUser(), newIssueCreatedID, "SF-Child", false)
       
        log.warn(" MOUNA CAMELIA 4 ==========================")
        log.warn("MOUNA CAMELIA ===== myissueID =====" + myissueID + " =====newissueTypeID =====" + newIssueCreatedID + " =====issueLinkType =====" + issueLinkType + " =====sequence =====" + sequence + " =====authenticationContext.getLoggedInUser() =====" + authenticationContext.getLoggedInUser())

        newissue.link(10070, issue)

        Collection < ProjectComponent > componentList2 = issue.getComponents()
        log.warn("MOUNA CAMELIA COMPONENT LIST 2 " + componentList2)
        componentList2.removeAll(issue.getComponents())
        log.warn("MOUNA CAMELIA COMPONENT LIST 2 " + componentList2)
        projectComponentManager.updateIssueProjectComponents(issue, componentList2)
    }
}

The problem is that after executing the first 2 automation rules, nothing changes and I need to do a refresh to see the results of the 2 first automation rules.  How can I see the effects of the automation rule without hitting the refresh button? 

1 answer

2 votes
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 24, 2023

Hi @Mouna Hammoudi 

The Jira views are not dynamic. There is no event chain that causes issue views to refresh when the underlying data is changed. This will only happen if you perform an action to cause the issue to refresh.

Mouna Hammoudi October 25, 2023

@Tom Lister , is it possible to have a refresh automatically made after the execution of an automation rule?

Suggest an answer

Log in or Sign up to answer