The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using ComponentAccessor () in Script Runner in Jira Cloud

Mayur Gaikwad/Tech PMO
Contributor
February 8, 2024

How to use ComponentAccessor () in Script Runner in Jira Cloud.

I'm trying to get customfield value through this method

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

2 votes
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 Champions.
February 8, 2024

Hi Mayur,

Cloud and DC are very different pieces of software, and although Scriptrunner for Jira only has one name, it is also two very different things.

DC code will generally not work on Cloud, the language and structures are very different.

You don't need to use componentAccessor on Cloud (you generally don't need it on DC any more, if you've got a version of Scriptrunner that enables HAPI).

Have a look at https://library.adaptavist.com/entity/update-cf-values-all-issues-cloud?tab=cloud - it shows you how to read and write custom fields with Cloud scripts

0 votes
Uday Kiran Bhaviri
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 Champions.
February 8, 2024

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def cField = customFieldManager.getCustomFieldObject("customfield_10301")

// You can also use by name

//Def cField = customFieldManager.getCustomFieldObjectsByName("customfieldname")[0]

def cFieldValue = issue.getCustomFieldValue(cField)

Hope this will be helpful.

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 Champions.
February 8, 2024

It is not, the question is for Cloud, not DC

Like Mayur Gaikwad/Tech PMO likes this
Uday Kiran Bhaviri
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 Champions.
February 9, 2024

Ohhh Thanks @Nic Brough -Adaptavist- 

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events