It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner/Behaviours how to get information of an issue when you know the issue name

Hello Community,

 

I am having a bit of trouble with Behaviours.

I would like to know if there is a way to grab the contents of an Issue if you know the name of an Issue.

In my Behaviour script I get the name of an Issue (provided by a custom field). From there I would like to use the name of the Issue to find that Issue in Jira and discover its resolution status, from there I would like to have a conditional statement that if a certain Issue is resolved then I do something, else I do nothing.

I appreciate any help!

-Roberto

 

My Script currently looks as follows:

def formField = getFieldById(getFieldChanged()) //Grab the field my behaviour is attached to

def issueName = formField.getValue() // Grab the value in the field a.k.a the name of an issue in Jira

 

2 answers

2 accepted

1 vote
Answer accepted

Hey @Roberto Luces

What Aleksandr said is not wrong, but there is an easier way. You can use the variable underlyingIssue, so if you are in any screen, except the Create Issue (which I guess this is not the case) then youcan use someth like 

log.debug "Issue is $underlyingIssue"

// the issue does no exist (probably you are in a create issue screen)
if (! underlyingIssue) {
return
}

// those are saved values in the issue and NOT necessary the current values in the form, use
def reporter = underlyingIssue.reporter?.displayName
def description = underlyingIssue.description

// in order to get the current value in the form
def descriptionValueInForm = getFieldById("description").value

So the underlyingIssue wll be an Issue

regards, Thanos

Hey @Thanos Batagiannis -Adaptavist- 

Thank you for the response, just like Alek's this worked wonderfully as well. 

I apprecaite you taking the time to help me out with this!

-Roberto

Hi @Thanos Batagiannis -Adaptavist- ,

 

What I'm noticing is that it works fine when viewing the create screen for the first time, but when I change the issueType I get the following error message:

2019-09-05_14-09-19.png

 

My script is:

 

def desc = getFieldById("description")

def defaultValue = """
h2. Overview

As a user, I would like to...

h2. Outcome

The outcome of this story should be...

h2. Value

The reason why we're doing this is...

h2. Acceptance Criteria

* Step 1
"""

if (! underlyingIssue?.description && !desc.getValue()) {
desc.setFormValue(defaultValue)
}

Hi @Rafael Franco and welcome to community :P

This is intentional.

I don't remember exactly in which version we introduced it, but the reasoning behind it, is that if you have written something in a text area, and then make a change that will wipe out the text in that area, then show that kind of flag.

But we are open to suggestions.

Regards, Thanos 

Thanks @Thanos Batagiannis -Adaptavist- for the warm welcome ;)

 

Yeah I get it, but isn't there a way to say if the field is not empty don't show the flag?

Like IC Admin likes this

Hello @Thanos Batagiannis -Adaptavist- , 

The preservation of the values when a different Issue Type is selected is understandable.
But what's also weird is that when you select back the Issue Type that had default values for description, the description gets overwritten.
What workaround can be applied?

0 votes
Answer accepted

Hi Roberto,

you can obtain IssueManager and then use it methods like getIssueObject, getIssueByCurrentKey etc.

import com.atlassian.jira.component.ComponentAccessor;

IssueManager issueManager = ComponentAccessor.getIssueManager();

Thank you for the response @Aleksandr Zuevich It worked like a charm!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Opsgenie

Two Chances to Improve your Incident Management Workflow

Hi there!  We all know that incidents can be messy, but they happen. Managing your response and planning ahead can make a *huge* difference in the duration and chaos of an incident. We have ...

144 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you