Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to set custom check box to yes through scriptfield code?

Edited

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 

 

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Joshua Yamdogo @ Adaptavist
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.
Nov 27, 2017

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 ?

 

Joshua Yamdogo @ Adaptavist
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.
Nov 28, 2017

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

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
}
Daniel Yelamos [Adaptavist]
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.
Nov 29, 2017

Suresh:

Why don't you use behaviours?

Cheers!

Dyelamos

@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"] })

}

}

 Capture.PNG

0 votes
Alexey Matveev
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.
Nov 21, 2017

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)

Thank you Matveev

We are getting error at same line and saying can not find matching method.

issue.setCustomFieldValue(cf, optionsToSelect)

 

Alexey Matveev
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.
Nov 22, 2017

What is your Jira version?

Daniel Yelamos [Adaptavist]
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.
Nov 22, 2017

Suresh

Is this error a static field checking? Or is it an actual exception?

Cheers!

DYelamos

Static check type

 

static.png

Alexey Matveev
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.
Nov 22, 2017

It is strange. Try like this

issue.setCustomFieldValue(cf, (Object) optionsToSelect)

What is your Scriptrunner version?

Daniel Yelamos [Adaptavist]
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.
Nov 22, 2017

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.

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])

@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?

Daniel Yelamos [Adaptavist]
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.
Nov 24, 2017

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

Dyelamos,

I am running this code in script field, may i know the log location.Setting Early Access through EA Pass script field.

 

setting earaly acess though EA-Pass scriptfiled.pngRegards,

Suresh

Daniel Yelamos [Adaptavist]
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.
Nov 24, 2017

Suresh:

We log to the atlassian main log.

Regards.

Dyelamos

We didn't find in the logs,

do we need add above code in the workflow post function?

Can we achieve this through script field?

TAGS
AUG Leaders

Atlassian Community Events