Forums

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

Cannot copy Checkbox Customfield values from Epic to Child using Behaviours

Rob Berube
Contributor
June 11, 2018

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)

 

1 answer

1 accepted

0 votes
Answer accepted
Joanna Choules
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 19, 2018

Hi Rob,

What is the type of the value you are getting back from EpicChapterField before you convert it to a string?

J

Rob Berube
Contributor
June 20, 2018

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events