Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set Select List Custom field from scriptrunner clone issue postfunction.

Hello Everyone, We are using Jira 7.6.4 and Scriptrunner 5.4.11, The task is to autopopulate a Selectlist customfield in Jira on the target issue. I have tried variuos scripts from the blog but none of them are working for me. Is something changed on Scriptrunner plugin recently? Can someone help me to get the correct script including the correct packages. 

 

I have tried the below scripts:

 

CustomField customField = customFieldManager.getCustomFieldObject("customfield_17100");

OptionsManager optManager = ComponentAccessor.getOptionsManager();
Options options = optManager.getOptions(customField.getRelevantConfig(issue), null));

Option newOption = options.getOptionById("Campaign"); // Check your option id

ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(customField), newOption );

customField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());

 

===============*=======================

 

import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Solution")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == 'Campaign'
}
issue.setCustomFieldValue(cfSelect, value)

 

 

1 answer

Hello @Vineet Kumar

try this

 

import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Solution")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == 'Campaign'
}
issue.setCustomFieldValue(cfSelect, value)

Thanks for the response Mark, I have already tried the above option, I am getting the below error.

 

Caused by: java.lang.ClassCastException: com.atlassian.jira.issue.customfields.option.LazyLoadedOption cannot be cast to java.util.Collection
at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:39) [jira-api-7.6.4.jar:?]
at com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:81) [classes/:?]
at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1014) [osworkflow-2.9.0-atlassian-1.jar:2.9.0-atlassian-1]
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1407) [osworkflow-2.9.0-atlassian-1.jar:2.9.0-atlassian-1]
at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:606) [osworkflow-2.9.0-atlassian-1.jar:2.9.0-atlassian-1]
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:742) [classes/:?]

Try enclosing the value within a collection. 

import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Solution")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == 'Campaign'
}
issue.setCustomFieldValue(cfSelect, [value])

I did something similar and it worked for me. 
This is what I have:

 Issue newIssueObject = ComponentAccessor.getIssueManager().getIssueByKeyIgnoreCase(newIssueID.toString().trim())

def customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField targetProjectBoardField = customFieldManager.getCustomFieldObject("customfield_10144")
String targetProjectBoardFieldValue = newIssueObject.getCustomFieldValue(targetProjectBoardField)

log.info "Current Project Board Value for target issue ("+newIssueID.toString().trim()+") is:" +targetProjectBoardFieldValue


if(targetProjectBoardFieldValue!=null && !targetProjectBoardFieldValue.equals("") && targetProjectBoardFieldValue.length()>1){

log.info "Updating Target Issue Project Board"
OptionsManager optManager = ComponentAccessor.getOptionsManager();
Options options = optManager.getOptions(targetProjectBoardField.getRelevantConfig(newIssueObject));
log.info "Available Options: " + options
Option newOption = options.getOptionById(Long.parseLong(affectedBoardsFieldValue));
log.info "Identified Option: " + newOption

def fieldConfig = targetProjectBoardField.getRelevantConfig(newIssueObject)
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.optionId.toString().trim() == affectedBoardsFieldValue.toString().trim() }

log.info "Final Value:" + value

def changeHolder = new DefaultIssueChangeHolder()
def issueCustomFieldValues = newIssueObject.getCustomFieldValue(targetProjectBoardField)
log.info "issueCustomFieldValues: "+issueCustomFieldValues
ModifiedValue mVal = new ModifiedValue(issueCustomFieldValues, [value])
log.info "mVal: "+mVal
targetProjectBoardField.updateValue(null, newIssueObject, mVal, changeHolder)

log.info "Target Issue Project Board has been updated."
log.info "Validation - " + newIssueObject.getCustomFieldValue(targetProjectBoardField)
}

 Modify per your needs.

Like # people like this

Thank you so much @Gundlupet Sreenidhi .

The below script works fine.

import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Solution")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == 'Campaign'
}
issue.setCustomFieldValue(cfSelect, [value])

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

⚡️NEW Group for Confluence Cloud Admins

Calling all Confluence Cloud Admins!  We created a new Community Group to support your unique needs as Confluence admins. This is a group where you can ask questions, access resou...

69 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you