Post function create: set custom field not setting on subtask using Groovy

Will R August 13, 2013

The subtask creates based on the issue type selected....this works alone but when I add

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Department'}
issue.setCustomFieldValue(cf, "First Line")

in the Additional issue actions in the workflow editor


The subtask isn't created and obviously that custom field isnt updated.

Any ideas?

Thx in advance.

The result evaluated to *assertion error*
assert cfValues['Department'].class == "Open".class
       |       |              |     |         |
       |       Open           |     false     class java.lang.String
       |                      class com.atlassian.jira.issue.customfields.option.LazyLoadedOption

2 answers

1 accepted

3 votes
Answer accepted
Will R August 15, 2013

I managed to get it to work.

You can see what I added...

thanks again for the start

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager


def componentManager = ComponentManager.instance
def optionsManager = componentManager.getComponentInstanceOfType(OptionsManager.class)
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Department'}
if(cf!=null){
def fieldConfig = cf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).find {it.value == "First Line"}
issue.setCustomFieldValue(cf, option)
}

JamieA
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.
August 16, 2013

nice one...

1 vote
RambanamP
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.
August 13, 2013

i think you are trying to set field value for select list, if yes then try with following code

def customFieldManager = componentManager.getCustomFieldManager()
def cf  = customFieldManager.getCustomFieldObjectByName("Department");
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)  
if(cf!=null){
IssueContextImpl issueContext = new IssueContextImpl(issue.getProjectObject(), issue.getIssueTypeObject());
def fieldConfig = cf.getRelevantConfig(issueContext)
def option = optionsManager.getOptions(fieldConfig).find {it.value == "First Line"}
issue.setCustomFieldValue(cf, option)
}

Will R August 13, 2013

I tried this, but returned same result. No subtask created. Just the parent task.

It is a drop down list for this particular field yes.

RambanamP
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.
August 13, 2013

can you share your code?

Will R August 13, 2013

Will R August 13, 2013

Hey again, thanks for the quick reply.

I didn't code much I just used Script Runner built in module in the work flow editor.

I copied your example as is into the additional options.

I'll upload screenshot.

Will R August 14, 2013

Any further ideas? if it sa standard text box then this works perfect. but its a drop down.. so I dont know how to modify this to make the drop down be set specifically

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Department'}
issue.setCustomFieldValue(cf, 'my value')


JamieA
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.
August 14, 2013

Rambranam's code is more or less correct. Do you have a custom field option called "First Line" - case-sensitive?

There are a few examples on this forum on how to set a select list value.

Add some debug lines to make sure you are getting an option value.

Will R August 14, 2013

Hey there..

I do have that as an option... its actually the first option....

Will R August 14, 2013

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: componentManager for class: Script75

This is the output from condition tester.. though I'm not sure if this can be tested there

Will R August 15, 2013

Sorry Jamie,

I dont have much experience with this code or Jira in general. in reality I won't get much more complex here than populating fields automatically based off the issue type of the parent task.

I'm not sure how to add debug lines.. the syntax to get the information I'm looking for.

the parent task issuetype is "Support"

the subtask issuetype is "Technical Task"

Both screen layouts have the custom field drop down "Department"

I know the code looks sound as you said... I really dont understand why its not working....

looks like I might have to have people just do dupliacte work, add parent.. then manually add subtask with the fields manually being entered :(

Thanks for trying guys.

Will R August 15, 2013

UPDATE: am getting this error repeatedly in the logs.


Script136.groovy: 5: unable to resolve class IssueContextImpl
@ line 5, column 18.
IssueContextImpl issueContext = new IssueContextImpl(issue.getProjectObject(), issue.getIssueTypeObject());
^

Script136.groovy: 5: unable to resolve class IssueContextImpl
@ line 5, column 33.
IssueContextImpl issueContext = new IssueContextImpl(issue.getProjectObject(), issue.getIssueTypeObject());

Will R August 15, 2013

now am just getting this....

Caused by: groovy.lang.MissingPropertyException: No such property: componentManager for class: Script25

Suggest an answer

Log in or Sign up to answer