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
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);
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 NowOnline 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.