Hello,
I am trying to set value of custom field "Billing" (type: single select) to "Billable" in create issue post function. Field "Billing" has 2 options: "Billable" and "Non-Billable". Value "Non-Billable" is set as fields default value.
For setting the field we are using scriptrunner scripted post function. code:
import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.customfields; def cf2 = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Billing"} def fieldConfig = cf2.getRelevantConfig(issue); value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Billable' } issue.setCustomFieldValue(cf2, value);
I can't make it work.
Can somebody help me to figure this out ?
Thank you in advance!
Where is customFieldManager defined? You need:
def customFieldManager = ComponentAccessor.getCustomFieldManager()
Defining customFieldManager helped - no errors in logs, but the field still has its default value. I tried to change the fields default value to "None" the field was empty after creating a new issue. Strange is that on other transitions the scripted post function works, only on create issue I am unable to get it work. It seems that problem is positioning of the post function in create issue. What do you think about it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
for the API you've used, the post-function needs to be at the top of the list of post-functions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Jamie, I would like to ask one additional question. It is possible on create issue transition setup a custom field value depending on the issue key. I mean something like this: {source} if (issue.key.contains("TBT")) { set field value } {source} Using this approach is not possible because if the post function is placed before "creates issue originally" it throws an null pointer exception.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Julius
If you are still looking for this, I found this worked as a way of updating a custom field:
.... DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder() customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), value.toString()), issueChangeHolder) ....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie Echlin [Adaptavist] anything new in this matter? Can you help with it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Scripted post-function is not first but is right after post function "Creates the issue originally."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Jamie, error was with the last import I fixed this by putting this lane as comment. trying running the script again ended in this error: "at Script54.run(Script54.groovy:6) groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script54"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks reasonable... is that the first post-function? Any errors in logs?
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.