Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to update sub-taks custom fields values when parent issue is updated using script runner?

mani@123
Contributor
June 27, 2019

Hello All,

I am able to update the sub-task issue custom field values(Text box) when parent issue is updated using below script in script listener:

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

def log = Logger.getLogger("com.hpe.cf")
log.setLevel(Level.INFO)
def partChange = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Part Number"}
def partDescChange = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Part Number Description"}
def partRgChange = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Purge Region"}

if (partChange || partDescChange || partRgChange) {
//log.info( "Value changed from ${change.oldstring} to ${change.newstring}")
// your actions if the field has changed
def subtasks = event.issue.getSubTaskObjects()
String fName = ""
String fValue = ""
if(partDescChange) {
fValue = partDescChange.newstring
fName = "Text Field name"
} else if(partRgChange) {
fValue = partRgChange.newstring
fName = "Text Field Name"
} else {
fName = "Text Field name"
fValue = partChange.newstring
}
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(fName)
if (subtasks){
subtasks.each {it ->
log.info(customField)
((MutableIssue) it).setCustomFieldValue(customField, fValue)
ComponentAccessor.getIssueManager().updateIssue(event.user, ((MutableIssue) it), EventDispatchOption.DO_NOT_DISPATCH, false)
log.info("******Updated*****")
}
}
}

 

 

 But when i am trying to update the single select list and check Box custom fields values using above script is not working. 

Can any one please help me with this issue. I am new to groovy script.

Thanks in Advance,

Mani

1 answer

1 accepted

0 votes
Answer accepted
fjodors
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 27, 2019

Hi

For select list custom field you need to import options manager and get all options firstly.
Try something like this:

//select list custom field ID is 123456
//select list custom field has options YES and NO
//your subtask is issueToUpdate

import com.atlassian.jira.issue.customfields.manager.OptionsManager
...
long customfieldID=123456;
def selectCustomField=customFieldManager.getCustomFieldObject(customfieldID);
def fieldConfig = selectCustomField.getRelevantConfig(issueToUpdate)
def optionsManager = ComponentAccessor.getOptionsManager();

def optionYes = optionsManager.getOptions(fieldConfig).find {it.value == "YES"}


issueToUpdate.setCustomFieldValue(selectCustomField, optionYes);
issueManager.updateIssue(event.getUser(), issueToUpdate, EventDispatchOption.ISSUE_UPDATED, false);

mani@123
Contributor
June 30, 2019

It helped. Thank you

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events