Hi all,
I'm trying to use ScriptRunner Behaviours to copy the Epic's Chapter Field to the child task. I tried to follow the instructions here but I'm stuck:
https://scriptrunner.adaptavist.com/5.4.7/jira/recipes/behaviours/setting-default-fields.html
I'm able to get the Epic's value from the field, the problem is applying those values to the child. Here's the code I have currently (some mention of description is in the code so that i can see the values). I think the problem is with this:
def optionsToSelect = options.findAll { it.value in EpicChapterFieldVal }
that the values i get from the epic are in a string and not in a list so that when i pass the values to the optionsmanager it doesnt know what to return. I can confirm I am able to get the values from the Epic but i cannot get the values to be applied to the checkbox field. Any help would be great, I've been bashing my head against this wall for a few days now.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.jira.groovy.user.FieldBehaviours
//Get the epic link from the current issue
FormField parent = getFieldByName("Epic Link")
//get the key of the epic
parentIssueId = parent.getFormValue().replaceAll("key:","")
//
IssueManager issueManager = ComponentAccessor.getIssueManager()
//get the epic issue itself
MutableIssue parentIssue = issueManager.getIssueObject(parentIssueId)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// Get the checkbox option value as a String
def EpicChapterField = customFieldManager.getCustomFieldObjectByName("Chapter")
def EpicChapterFieldVal = parentIssue.getCustomFieldValue(EpicChapterField).toString()
// Get a pointer to my select list field
def selectList = getFieldByName("Chapter")
// Get access to the required custom field and options managers
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(selectList.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
// Logic to do some actions depending on what check box value is selected
//def desc = getFieldById("description")
//desc.setFormValue(EpicChapterFieldVal)
def optionsToSelect = options.findAll { it.value in EpicChapterFieldVal }
//desc.setFormValue(EpicChapterFieldVal)
selectList.setFormValue(optionsToSelect*.optionId)
Hi Rob,
What is the type of the value you are getting back from EpicChapterField before you convert it to a string?
J
Hi Jake,
Thanks for taking the time to try and help me out, however, I did happen to solve it myself using the code here:
https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/subtask-default-fields.html
cheers,
Rob
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.