How do i get my script to use current data in post function?

I have this post function script which finds all the subtasks of an issue and sums up a specific field.   It fires when i update the subtask.  The problem is that if i change the data (in the subtask) the script wont read it.  It uses whatever the old data was before i updated.  My script is below. (Dont mind all the debugging messages, im totally new at this)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import org.apache.log4j.Level
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.log4j.Logger
import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.IssueManager

import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def changeHistoryManager=  ComponentAccessor.getChangeHistoryManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def cField = customFieldManager.getCustomFieldObjectByName("Initial Architecture LOE")
def total = 0
def holder = 0
def log = Logger.getLogger("com.eq.CreateSubtask")
def parentIssue
log.setLevel(Level.DEBUG)


if(issue.getIssueType().isSubTask()){
    //get the parent issue
    parentIssue = issue.parentObject
    //get all the custom fields
        log.debug("phil total: Im Here")
}
   


def subTasks = parentIssue.getSubTaskObjects()
subTasks.each {
   //log.debug("phil: inside")
   //log.debug( "phil issuetype:"+it.getIssueType()+" resolution:"+it.getResolution())
    log.debug("phil total1: "+it.getCustomFieldValue(cField))
 holder = (it.getCustomFieldValue(cField)as Double) as Integer
    if (holder == null){
        holder = 0
    }
    log.debug("phil total2: "+holder)
    if (it.getIssueType().name == "Feature"){
      total = total + holder}
}

log.debug("phil total: "+total)

 

2 answers

1 accepted

Actually i solved it.  I just put an if statement to get the data from the current subtask instead of the subtask related to the parent. 

0 vote
Sam Hall Community Champion Apr 06, 2017

Are you using ScriptRunner for JIRA here?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published yesterday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

446 views 6 7
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you