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

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!
September 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-
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.
October 2, 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!
October 2, 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