Forums

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

Having trouble with accessing fields with scripts

CJ_Marchand
Contributor
May 11, 2023

Hi everyone.  

I am writing some code to access fields but it is not working. 

First off this code is in the Initializer section of a behavior.

In the code below at line 14 I am trying to get the value of the sys "Work Item Type" field but it is returning null.  I know at this point no selection has been made but I would think it would return the default value.  

On line 20 I am trying to get access to the current issue to get a hook into the custom fields.

It is also failing.

 

Code.PNG

Any help would be appreciated. 

Thanks,

C.J. 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Neta Elyakim
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.
July 18, 2018

It's will work on Listener like that

if(issue.fields.issuetype.subtask == true){    
String parentkey= issue.fields.parent.key  
}

and if you are in script console do this:

 def issueKey = 'COPY-19' // enter you sub task key here

def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
def parentIssue = result.body.fields["parent"]
return parentIssue["key"]
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
TAGS
AUG Leaders

Atlassian Community Events