Based the value of another field value we need to set checkbox=yes,
I am trying with following script code.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfig
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Early Access")//checkBox
def fieldConfig = cf.getRelevantConfig(issue)
def eaIssues = getCustomFieldValue("EA Program Issue")
//check esIssues empty or not, and check to "Yes" if is not empty
if (eaIssues) {
issue.setCustomFieldValue(cf, "Yes")//setting checkBox =Yes
return
}
else {
return null
}
I am getting unsrloved error at
issue.setCustomFieldValue(cf, "Yes")//setting checkBox =Yes
Hi @Suresh,
It looks you are trying to set another custom field within your scripted field. Is that correct?
You absolutely cannot set values using scripted fields. Our documentation on the website about script fields states this:
You can use Groovy to display a "calculated" custom field on an issue. You cannot make any modifications within a calculated field… the only thing you can do is pull information from the current issue, or other issues, or outside of the JIRA environment altogether, and display it.
Setting custom field values in a script field will result in numerous errors including inconsistency of values.
It looks you are trying to set another custom field within your scripted field. Is that correct? YES
Ok, can we create Checkbox type script field ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Suresh,
I would suggest using a Script Listener or Post-function to set the other custom field. You could set up a script listener that fires every time the issue is updated and it will set the checkbox to "Yes."
Using a post-function, you could set the checkbox to "Yes" on a specific transition, like when the issue is created.
Which one do you think will work better for you?
Josh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Script Listener will be better for us,I am trying following code in script listener: selected custom listner and then "update issue event".But still no luck.Any thing I am missing here.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfig
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Early Adopter")//checkBox
//def fieldConfig = cf.getRelevantConfig(issue)
def eaIssues = getCustomFieldValue("EA Program Issue")
//check esIssues empty or not, and check to "Yes" if is not empty
if (eaIssues) {
issue.setCustomFieldValue(cf, "Yes")//setting checkBox =Yes
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Suresh:
Why don't you use behaviours?
Cheers!
Dyelamos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Daniel Yelamos [Adaptavist] I am trying as follows in behaviours
But still no luck. Am I missing any thing here.
if (formContents["id"] == null) {
def eaIssues = getFieldByName ("EA Roadmap Issues")
def eAdop = getFieldById ("Early Adopter") //checkbox
String cateval = (String) eaIssues.getValue()
if (cateval != null){
eAdop.setFormValue(options.findAll { it.value in ["Yes"] })
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I guess you need to set it like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfig
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Early Access")//checkBox
def config = cf.getRelevantConfig(issue)
def options = ComponentAccessor.getOptionsManager().getOptions(config)
def optionsToSelect = options.findAll { it.value in ["Yes"] }
issue.setCustomFieldValue(cf, optionsToSelect)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is your Jira version?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Suresh
Is this error a static field checking? Or is it an actual exception?
Cheers!
DYelamos
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.
It is strange. Try like this
issue.setCustomFieldValue(cf, (Object) optionsToSelect)
What is your Scriptrunner version?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Static field checking doesn't actually mean that it isn't going to work. I agree with Alex that this is bizarre, however I would recommend that you save the script and check that it works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Updated the script field code with static error and tried but still no luck, initially i just want check the checkbox =yes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Early Access") // Checkboxes is the NAME of my custom field
def fieldConfig = cf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null)
issue.setCustomFieldValue(cf, [option])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Daniel Yelamos [Adaptavist] Can we have any alternate approach to set CheckBox =Yes, based on another custom field value is not empty.
Can we set the above code in scriptfield?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Suresh, sorry for the late response, we've been a bit busy in Adaptavist this week.
I've looked through our code and I can't find a particular way of setting the checkbox.
Let's do this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Early Access") // Checkboxes is the NAME of my custom field
def fieldConfig = cf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getRootOptions()
log.debug("THE OPTIONS FOR THE CHECKBOX ARE:" + option)
This way, we can see what the options for the configuration of the field is, and set the appropriate one after checking the logs.
Let me know if I can help you further.
Cheers!
Dyelamos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dyelamos,
I am running this code in script field, may i know the log location.Setting Early Access through EA Pass script field.
Regards,
Suresh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Suresh:
We log to the atlassian main log.
Regards.
Dyelamos
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.