HI i have a scenario where if i deleted some data from a custom field in epic same value should be removed from custom field of the Parent issue(Epic's Parent Issue).
I am able to do it for one Epic, but suppose i have a parent issue and it contains 2 epic , Epuc-1 and Epic-2. i deleted one value from Epic-1 and its removed from parent issue too, but how can i iterate Epic-2 issue? can we do that based on issue key? and suppose the value which has been removed from epic-1 but its present in epic-2 , then how can it wont remove the value from parent? below is my code for one epic value removal, but need help to for multiple epics iteration.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService
import org.apache.log4j.Logger
import org.apache.log4j.Level ;
log.setLevel(Level.DEBUG) ;
Issue epicIssue = event.issue
String issuetype = epicIssue.getIssueType().getName()
if(issuetype == "Epic"){
if (event?.getChangeLog()?.getRelated("ChildChangeItem")?.find { it.field == "Impacted Application/s" }) {
def changeItem = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find { it.field == "Impacted Application/s" }
String[] newValue = changeItem.get("newstring").toString().split(';')
String[] oldValue = changeItem.get("oldstring").toString().split(';')
log.debug("New Value: "+newValue)
log.debug("Old Value: "+oldValue)
//Split and get array of entries per CSI
if( (oldValue[0] == 'null') || newValue.size() < oldValue.size()){
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def ImpactedAppField = customFieldManager.getCustomFieldObjectByName("Impacted Application/s")
String ImpactedAppValue = epicIssue.getCustomFieldValue(ImpactedAppField)
log.debug("Value in Impacted App field is: "+ImpactedAppValue)
log.debug("Value in Event is: "+ event?.getChangeLog()?.getRelated("ChildChangeItem")?.find { it.field == "Impacted Application/s" })
def cf = customFieldManager.getCustomFieldObjectByName("Parent Link")
def parentValue = epicIssue.getCustomFieldValue(cf)
if(parentValue != null){
// log.debug("parent Value is: "+parentValue)
def issueManager = ComponentAccessor.getIssueManager() ;
Issue PlanviewIssue = issueManager.getIssueObject("" + parentValue);
// log.debug("Planview Issue is: "+PlanviewIssue)
String planviewImpactedApp = PlanviewIssue.getCustomFieldValue(ImpactedAppField)
log.debug("Planview Impacted Apps are: "+planviewImpactedApp)
if(planviewImpactedApp != null){
def userManager = ComponentAccessor.getUserManager()
ApplicationUser admin = userManager.getUserByName("INT_JIRA")
//String[] csis= separateCSI(ImpactedAppValue)
def Planview = planviewImpactedApp as List
// def Epic = ImpactedAppValue as List
String[] impacted = ImpactedAppValue.split("\\s*[;]\\s*");
// log.info "Printing impacted for Epic Issuee Value : --" + impacted
List<String> fixedLenghtList1 = Arrays.asList(impacted);
ArrayList<String> listOfEpicValues = new ArrayList<String>(fixedLenghtList1);
log.info "Printing listOfEpicValues For Epic Issuee Value : --" + listOfEpicValues
String[] planViewImpact = planviewImpactedApp.split("\\s*[;]\\s*");
// log.info "Printing planViewImpact for Parent Issuee Value : --" + planViewImpact
List<String> fixedLenghtList = Arrays.asList(planViewImpact);
ArrayList<String> listOfPlanViewValues = new ArrayList<String>(fixedLenghtList);
ArrayList<String> newList = new ArrayList<String>(fixedLenghtList);
// log.info "Printing listOfPlanViewValues before Subtract For Parent Issuee Value : --" + listOfPlanViewValues
// ArrayList<String> newList = listOfPlanViewValues
log.debug("Printing New List Parent --- before Subtract ---->>>>" + newList)
// def newList = listOfString as String
if(planviewImpactedApp != ImpactedAppValue){
// listOfString.intersect(listOfString1)
listOfPlanViewValues.removeAll(listOfEpicValues)
//Planview.intersect(Epic)
log.debug("Printing listOfPlanViewValues after Subtract --->>>>" + listOfPlanViewValues)
log.debug("Printing newList before Single Subtract --->>>>" + newList)
newList.removeAll(listOfPlanViewValues)
log.debug("Printing New List--- newList---->>>>" + newList)
def planviewValues = newList as String
def str = planviewValues.split("\\s*[;]\\s*"); // added for separating the list into string
def planviewValue = str as String// added for separating the list into string
log.debug("Printing PlanView Valuessssssss :-->>>>>>>>" + planviewValues)
// log.debug("Printing planviewValue :-->>>>>>>>" + planviewValue)
// log.debug("Both Parent and Child fields are not same>>>>" + planviewImpactedApp)
/* String[] csis= separateCSI(planviewValues)
String newAppList = ""
csis.each { String csi ->
newAppList += csi +"; "
} */
modifyValue(admin,PlanviewIssue,ImpactedAppField, planviewValue)
/// modifyValue(admin,PlanviewIssue,ImpactedAppField, newAppList.substring(0,newAppList.length()-2))
}
}
else{
}
}
}
}
}
boolean modifyValue(ApplicationUser user, Issue issue, CustomField customField, String value){
IssueService issueService = ComponentAccessor.getComponent(IssueService);
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.addCustomFieldValue(customField.id, value)
def update = issueService.validateUpdate(user, issue.getId(), issueInputParameters)
/* validate update info and execute update */
if (update.isValid()) {
IssueService.IssueResult status = issueService.update(user, update)
if (!status.isValid())
{
for (def error : status) {
}
} else {
}
} else {
IssueService.IssueResult status = issueService.update(user, update)
for (def error : status) {
}
}
return true
}
def String[] separateCSI(String apps){
def log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
//need to take out the [ ] that show up under my CSI's
apps = apps.trim()
log.warn(apps)
//if(apps.contains("\\[")) apps = apps.split("\\[")
def counter = 0
String[] result = apps.split(';')
result.each { String csi ->
if(csi.contains('[')){
String[] s = csi.split('\\[')
result[counter] = s[0].trim()
} else if(csi.contains('(')){
String[] s = csi.split('\\(')
result[counter] = s[0].trim()
} else if(csi.contains('-')){
String[] s = csi.split('\\-')
result[counter] = s[0].trim()
} else result[counter] = csi.trim()
counter++
}
//Change this line 10/15 from result to result.toUnique() to remove duplicates
return result.toUnique();
}
log.debug(""+epicIssue.key)
def String[] checkEpicForImpactedApp(String planviewKey, String impactedApp){
Issue epicIssue = event.issue
epicIssue.each{ String issueCount ->
}
return null;
}
any help will be appreciated.
Regards
Manas
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.