Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


How do I set custom fields using the IssueInputParameters method for select lists and dates?

I have a groovy script that performs the following in a workflow post function:

  • Creates a linked issue for each Insight Object value in a custom field

The script works however I now want to copy the value of two custom fields into the linked issues on create. One is a Select List (Single Choice) and the other is a Date Picker. I am trying to use the addCustomFieldValue method but it seems to be configured for a String. Any help would be much appreciated.

Code (I have marked up the lines causing the problem with /* comments):

// Required library imports
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.config.manager.PrioritySchemeManager
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import customRiadaLibraries.insightmanager.InsightManagerForScriptrunner
import org.apache.log4j.Level
import org.apache.log4j.Logger

// This annotation allows the import of com.riadalabs classes
@WithPlugin('com.riadalabs.jira.plugins.insight') insightPlugin

issue = issue as MutableIssue //this helps with IDE autocomplete and Script Editor status type checking

def mylog = Logger.getLogger("com.acme.workflows")

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def customFieldInsightA = customFieldManager.getCustomFieldObject(12001)
def CusValueA = issue.getCustomFieldValue(customFieldInsightA) as List<ObjectBean>

def customFieldInsightB = customFieldManager.getCustomFieldObject(11801)

def cfDataRequired = customFieldManager.getCustomFieldObject(12100)
def cfDataRequiredValue = issue.getCustomFieldValue(cfDataRequired)

def cfExitDate = customFieldManager.getCustomFieldObject(12002)
def cfExitDateValue = issue.getCustomFieldValue(cfExitDate)

def issueService = ComponentAccessor.issueService
def constantsManager = ComponentAccessor.constantsManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def prioritySchemeManager = ComponentAccessor.getComponent(PrioritySchemeManager)
//eachWithIndex iterates through following code for all Custom Field values creating the linked issues
CusValueA.eachWithIndex { item, index ->"item="+item)"index="+index)

// the project key under which the issue will get created
final projectKey = 'ABC'
// the issue type for the new issue
final issueTypeName = 'Task'
// the priority of the new issue
final priorityName = 'Medium'

def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey)
assert project : "Could not find project with key $projectKey"

def issueType = constantsManager.allIssueTypeObjects.findByName(issueTypeName)
assert issueType : "Could not find issue type with name $issueTypeName"

// get the reporter of the current issue
def reporter = issue.getReporter()
// get the current user
def currentUser = loggedInUser

// if we cannot find the priority with the given name or if this is null, then set the default priority
def issueContext = new IssueContextImpl(project, issueType) as IssueContext
def priorityId = constantsManager.priorities.findByName(priorityName)?.id ?: prioritySchemeManager.getDefaultOption(issueContext)

def issueInputParameters = issueService.newIssueInputParameters().with {
setReporterId(loggedInUser.username) // set the reporter of the sub-task as the current user
setSummary("Customer Decommissioning: " + item.label)
addCustomFieldValue(customFieldInsightB.idAsLong, item.objectKey) // add the current item (insight object) to the field in the issue
addCustomFieldValue(cfDataRequired.getId(), cfDataRequiredValue) /* This line of code causes the script to become invalid, I want to set the custom field value for Select List Single Choice in child same as parent*/
addCustomFieldValue(cfExitDate.getId(), cfExitDateValue) /* This line of code causes the script to become invalid, I want to set the custom field value for Date Picker in child same as parent*/

def validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection

def result = issueService.create(loggedInUser, validationResult)
assert result.valid : result.errorCollection

// the name of the issue link
final String issueLinkName = "Relates"

// the sequence of the link
final Long sequence = 1L

def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def availableIssueLinkTypes = issueLinkTypeManager.issueLinkTypes
def linkType = availableIssueLinkTypes.findByName(issueLinkName)
assert linkType : "Could not find link type with name $issueLinkName. Available issue link types are ${availableIssueLinkTypes*.name.join(", ")}"

def childTask = result.issue
ComponentAccessor.issueLinkManager.createIssueLink(,,, sequence, loggedInUser)

}"Field Value= "+ CusValueA)


1 answer

For anyone interested in this, as a temporary fix I have used two scriptrunner post functions (copy field) positioned after the above custom script post function to reach the same end. Although I would find it preferable for all the actions associated with the create issue to be contained in the script :)

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events