Hi. Firstly, apologies if this is a bit basic - hopefully that'll translate into an easy answer!
I have a workflow set up to update a custom field to "No" whenever a certain status is transitioned to - that's performed via Scriptrunner post function (script is at the bottom of this post). Put simply, it doesn't work.
I have verrrrrrrrry little scripting experience so I've put this together from various sources. I've likewise looked at a couple of solutions already posted here but these haven't worked, which makes me think I'm missing something fundamental.
The custom field is called "RTS Buddying Complete?" and is a "Select list - single choice" type. The only choices are "No" which is the default, and "Yes."
When I transition to the appropriate status, I get a "Workflow Error" popup saying, "Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB java.lang.String cannot be cast to com.atlassian.jira.issue.customfields.option.Option
It seems that you have tried to perform an illegal workflow operation."
NB I can't open that link so I'm a bit stuck.
I've seen elsewhere that it might be because how I'm trying to update the field is incompatible with the select list, but - unless I'm missing something - I can't see what I need to do to get it to work.
Anyway, this is the script, which runs as a custom script post-function (inline script): I'm not even sure that I need the "Get custom field value" bit but I've included it here so you can see it in completion. It should be simple but it's really annoying me.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//get custom field object
def cfoBuddyComplete = customFieldManager.getCustomFieldObjectByName("RTS Buddying Complete?")
//get custom field value
def cfBuddyComplete = issue.getCustomFieldValue(cfoBuddyComplete)
//set value
issue.setCustomFieldValue(cfoBuddyComplete, 'No')
Is your post function running before the standard Update Change History function?
for select lists try
def cf = customFieldManager.getCustomFieldObjectByName("customFieldId=10807")
def cfConfig = cf.getRelevantConfig(issue)
value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Training' }
issue.setCustomFieldValue(cf, value)
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi. Is that meant to be all one line? How does that fit into the script I've drawn up? Where you've put "training", what do I replace that with?
I know it's a big ask but could you put what you've done into the context of the script I've included, as I have no idea looking at that what I need to change either within your part or mine. Like I said, a newbie!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Try this. If it doesn't work I'll try and refine it on my instance
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//get custom field object
//def cfoBuddyComplete = customFieldManager.getCustomFieldObjectByName("RTS Buddying Complete?")
def cf = customFieldManager.getCustomFieldObjectByName("RTS Buddying Complete?")
def cfConfig = cf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'No' }
issue.setCustomFieldValue(cf, value)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This snippet works on my instance - doesn't like multi-selects though in this form.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That works perfectly. I can't thank you enough!
Very very much appreciated.
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.