Hi folks,
I'm trying to set a checkbox through scriptrunner at creation of a subtask and when the parent is a specific ticlet type.
Here follows what I wrote in the listener. the triggering Event is "issue creation"
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.fields.FieldManager
import com.atlassian.jira.issue.CustomFieldManager;
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
def issueManager = ComponentAccessor.issueManager
def currentIssue = event.issue
def customField = customFieldManager.getCustomFieldObjectsByName("Richiesta Formazione")[0]
def fieldConfig = customField.getRelevantConfig(currentIssue)
def options = optionsManager.getOptions(fieldConfig)
def optionsToSet = options.findAll { it.value in ["SI"]}
def parent = event.issue.getParentObject()
// if the ticket is a subtask
if(currentIssue.issueTypeId.equalsIgnoreCase("10101")){
// il the parent is a type learning
if(parent.issueTypeId.equalsIgnoreCase("10502")){
// set checkbox to YES
currentIssue.setCustomFieldValue(customField, "SI")
}
}
the name of the Checkbox filed is "Richiesta formazione" and has one single possible value: "SI"
the error I get is: Cannot find matching method
Could you please help me?
Thank you in advance
/Pas
Hi Pas,
I don't have an environment to test it right now, but looking at your code, I guess the problem is setting the value.
First thing you should try: log the option value you have, when searching for "SI"
When this returns a valid value/id, you should pass this id to
currentIssue.setCustomFieldValue(customField, "SI")
instead of "SI", in your case optionsToSet
That should hopefully do the trick.
Hi Kai Sören,
thank yoy for your reply. I'm not sure If got what do you mean by log the option value when searching for "SI".
Sorry but I'm not familiar with scriptrunner.
BR Pas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pas,
no problem. I updated your code. Line 22 is the log I meant and line 33 shows the update with the option itself, instead of the option value. That should do the trick:
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.fields.FieldManager
import com.atlassian.jira.issue.CustomFieldManager;
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
def issueManager = ComponentAccessor.issueManager
def currentIssue = event.issue
def customField = customFieldManager.getCustomFieldObjectsByName("Richiesta Formazione")[0]
def fieldConfig = customField.getRelevantConfig(currentIssue)
def options = optionsManager.getOptions(fieldConfig)
def optionsToSet = options.findAll { it.value in ["SI"]}
//to check if its not empty
log.warn("option: " + optionsToSet.getValue())
def parent = event.issue.getParentObject()
// if the ticket is a subtask
if(currentIssue.issueTypeId.equalsIgnoreCase("10101")){
// il the parent is a type learning
if(parent.issueTypeId.equalsIgnoreCase("10502")){
// set checkbox to YES
currentIssue.setCustomFieldValue(customField, optionsToSet)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi and thank you again.
I'm still getting a couple of errors . Not sure it's a library issue or a type issue.
Do you have an idea?
/Pa
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.