Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unable to update Parent Issue's Custom Field while updating Child Issue's same Custom Field

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

 

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - Spring 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

134 views 3 16
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you