Forums

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

How do I create a scripted field with scriptrunner in Jira cloud?

James Mason March 20, 2023

I've been beating my head against this wall and lots of searches have been unfruitful.  I am trying to port over a simple scripted field from scriptrunner for jira server to one for jira cloud.  Here is the old script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue


def parentLink = issue.getParentObject();


return parentLink


How would I rewrite this in Jira cloud scriptrunner as I can find the field in the rest API but can't actually show the value.  Thanks in advance!

3 answers

1 accepted

1 vote
Answer accepted
James Mason March 22, 2023

I was able to solve this problem in a slightly different manner with this script:

def issueKey = issue.key


def resp = get("/rest/api/2/issue/${issueKey}")
.header("Content-Type", "application/json")
.asObject(Map)
.body
resp["fields"]["parent"]["key"]

0 votes
Kai Becker
Community Champion
March 20, 2023

Hi @James Mason 

welcome to the community. Scriptrunner Cloud is a little bit different than server.
You need to use the REST API to get the data you need.

Maybe this script will point you into the right direction: https://library.adaptavist.com/entity/sum-custom-field-related-epic-issues?tab=cloud

0 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 Leaders.
March 20, 2023

Welcome to the Atlassian Community!

Jira Cloud does not support scripted fields the way that server does.  You will need to use a standard custom field, and have your script populate it on change of data.

James Mason March 20, 2023

So i would need to take the built in field from advanced roadmaps that builds that parent link and dump it into another custom field to be able to retrieve it for viewing?

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.
March 20, 2023

Yes, exactly that.

On Server/DC, you can use a scripted field with "return <value from wherever>", but Cloud does not support the field type that SR injects on Server/DC, so we have to work with whatever field types that there is a REST API for.

It's not as good as the cleverness of proper scripted fields, because it has become a simple "copy field X to Y", but it works well enough for most (and we're working on proper scripted fields for Cloud with Atlassain)

Like # people like this
James Mason March 21, 2023

So how would I read that field?  I can see the parent key when I run a get against the issue endpoint but I just can't return it

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.
March 21, 2023

Same as you would read any other custom field.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events