Hi
I have a Custom Field in an Issue.Same Custom field is present in its Parent issue too.
My requirement is, when i have added any value in child issue , same will check with the parent issue's field and will be added if its not present.
I am able to fetch vaue from both Child and Parent Issue's Custom Field.
I am able to filter out the Unique one's too.
But when ever i am updating the Child issue the Parent is not Updated and no Value has been added.
I am doing this Using Listener , and i dont have much knowledge about these as m new to this.
Do we have any predefined Function for this ? or Specific Event? Any Help Will be Appreciated.
Below is my working Code.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Level ;
import org.apache.log4j.Logger ;
import com.atlassian.jira.issue.MutableIssue ;
import com.atlassian.jira.issue.fields.config.FieldConfig ;
import com.atlassian.jira.issue.customfields.option.Options ;
import org.apache.commons.collections.ListUtils;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.io.*;
import java.util.HashSet;
import java.util.Set;
import com.google.common.collect.ObjectArrays;
import java.util.Arrays;
import org.apache.commons.lang.ArrayUtils;
log.setLevel(Level.DEBUG) ;
// From here Child Issue Details Starts....
def issue = event.issue as Issue
def issueManager = ComponentAccessor.getIssueManager() ;
def customField = ComponentAccessor.getComponent(CustomFieldManager).getCustomFieldObject("customfield_10602")
log.debug("Printing Custom Field : --" + customField)
def impactedAppValues = customField.getValueFromIssue(issue) as String
log.info "Printing Custom Field with Issuee Value : --" + impactedAppValues
String[] elements = impactedAppValues.split("\\s*[;]\\s*");
log.info "Printing elements with Issuee Value : --" + elements
List<String> fixedLenghtList = Arrays.asList(elements);
ArrayList<String> listOfString = new ArrayList<String>(fixedLenghtList);
log.info "Printing listOfString with Issuee Value : --" + listOfString
// From here parent Issue Details Starts....
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Parent Link")
def parentValue = issue.getCustomFieldValue(cf)
log.info "Printing parentValue value :-----" + parentValue
def planviewProjectSide = ComponentAccessor.getComponent(CustomFieldManager).getCustomFieldObject("customfield_10602");
Issue PlanviewIssue = issueManager.getIssueObject("" + parentValue);
def parentCustomField = planviewProjectSide.getValueFromIssue(PlanviewIssue) as String
log.info "Printing parentCustomField value :-----" + parentCustomField
String[] elements1 = parentCustomField.split("\\s*[;]\\s*");
log.info "Printing elements for Parent Issuee Value : --" + elements1
List<String> fixedLenghtList1 = Arrays.asList(elements1);
ArrayList<String> listOfString1 = new ArrayList<String>(fixedLenghtList1);
log.info "Printing listOfString1 For Parent Issuee Value : --" + listOfString1
listOfString1.addAll(listOfString)
log.info "Printing listOfString1 Againnnnnnnnn For Combined Value of 1 & 2--" + listOfString1
listOfString1.unique()
log.info "Printing listOfString1 Unique Values of 1 & 2--" + listOfString1
//def parentCustomField1 = listOfString1
//log.info "Printing parentCustomField -----" + parentCustomField
/* From Here i have added code for duplicate Value or With Duplicate number checking or sorting value */
def listUniqueValues = []
def valuesAlreadySeen = new HashSet()
listOfString1.each { item ->
def value = item.split(" ")[0]
if (! valuesAlreadySeen.contains(value)) {
listUniqueValues << item
}
valuesAlreadySeen << value
}
log.info "Printing listUniqueValues" + listUniqueValues // working
log.info "Printing valuesAlreadySeen" + valuesAlreadySeen
//listUniqueValues.sort() { a,b -> a <=> b }.each { println it }
parentCustomField = listUniqueValues
log.info "Printing parentCustomField -----" + parentCustomField
Regards
Manas