Due to the reporting restriction on portfolio fields we are having to copy the parent link value into a standard text field so that we can report off of parent link. Below is the start of a listener I am working on, but can't get it to work. Any suggestions?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.index.IssueIndexingService;
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.LISTENER")
log.setLevel(Level.DEBUG)
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def parentLink = customFieldManager.getCustomFieldObjectByName("Parent Link")
def value = issue.getCustomFieldValue(parentLink)
def parentKey = value.key
def parentIssue = ComponentAccessor.issueManager.getIssueByCurrentKey(parentKey)
def portParentLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Portfolio Parent Link")
def changeHolder = new DefaultIssueChangeHolder()
def issueIndexManager = ComponentAccessor.getComponent(IssueIndexingService)
if (parentIssue == null)
{
log.debug ("Parent link value is null: End listener")
}
else
if (parentIssue != Null)
{
portParentLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(parentIssue),changeHolder)
}
issueIndexManager.reIndex(issue)
}
I figured out what was wrong and I have updated the script. now it is working.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.index.IssueIndexingService;
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.ParentLinkLISTENER")
log.setLevel(Level.DEBUG)
def issue = event.issue as Issue
log.debug "Test Debug"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def parentLink = customFieldManager.getCustomFieldObjectByName("Parent Link")
def parentLinkValue = issue.getCustomFieldValue(parentLink)
def portParentLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Portfolio Parent Link")
def changeHolder = new DefaultIssueChangeHolder()
def issueIndexManager = ComponentAccessor.getComponent(IssueIndexingService)
if (parentLinkValue == null)
{
log.debug "Parent link is null: End of Script"
}
else
{
log.debug "Parent link used: Update Porfolio Parent Link"
log.debug("Child Issue = " + issue)
def key =(String)parentLinkValue.getKey();
def summary =(String)parentLinkValue.getSummary();
log.debug("Parent Link = " + parentLinkValue + summary)
portParentLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(portParentLink),key + " "+ summary),changeHolder)
}
What aspect of it doesn't work? If you just run the code in the console, does it work? Does it produce the correct output? Does it update the issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.