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

Cannot get custom script to set a value

MHarvey
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Sep 28, 2023

Hello Everyone!

 

I have been pounding my head against a wall for days just trying to learn how to do a few basic things in a groovy script.  I have had some luck with post transition scripts, but now I am trying to do something that seems like it should be simple in an automation script.  I am just trying to set a value on a field - in this case a checkbox (and eventually a few other custom fields).

I have tried at least 30 examples from here on the forum, but all show me an error on the setCustomFieldValue and I do not understand why.  I have cut my code down to the bare minimum to try and get it working, so just the imports, the definitions, and the field I want to set.  The set line (which I have tried at least 7 variations of) always has the red mark indicating an error.  I am suspecting this is something simple, but has been buried in other examples so that my searches never find the small thing I need.

I have this in a scriptrunner automation set to run when the issue created and when I use a specific entry in the Summary, It is entered under a "Execute a ScriptRunner script":

 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf_VisTicket = customFieldManager.getCustomFieldObjectByName("HELP: Visible Ticket")

issue.setCustomFieldValue(cf_VisTicket, "Visible Ticket")

 

1 answer

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 02, 2023

Welcome to the Atlassian Community!

https://library.adaptavist.com/entity/basics-updating-customfields?tab=dataCenter shows us how to set almost every type of custom field that there is in Jira.

Your code does seem to be using HAPI in Scriptrunner though - is your version of Scriptrunner new enough to have HAPI?  If it is old enough to be pre-HAPI, you'll need to change your code to do it natively with the Jira API.

MHarvey
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Oct 02, 2023

I have referred to https://library.adaptavist.com/entity/basics-updating-customfields?tab=dataCenter many times, and that is how the setcustomfield above is formatted.  It appears my version of scriptrunner is 7.7.0, so I don't know about HAPI (I know I am not HAPI...).  The setcustomfieldvalue does work in post-functions though (using the issue.set{} ).

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events