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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,554,659
Community Members
 
Community Events
184
Community Groups

Behaviours/Groovy how can i get description field content on create issue screen?

Edited

Based on code example, located here i made behaviour with description template, but it not working right.

I guess, this part is not working

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

Because underlyingIssue not exists while creating new issue. Am i right?

 

So i tried to do something like this:

//issuetype 10004 = bug

//get some values
def descriptionField = getFieldById("description")
def issueTypeField = getFieldById("issuetype")
def issueTypeValue = issueTypeField.getValue()
def descriptionValue = descriptionField.getValue()
def descriptionValue1 = descriptionField.getFormValue()

//define template
def templateValue = """h5. Env:
h5. Version:

h5. Bug description

h5. Steps to reproduce:

h5. Expected result:

h5. Actual result: """.replaceAll(/ /, '') + " " + descriptionValue + " " + descriptionValue1 //i've added description values here, to see, if it contain something

// if description already contain template, and issueType changed from bug to another, clear form
if (descriptionValue == templateValue && issueTypeValue != 10004){
descriptionField.setFormValue("")
}

//If descriptionValue not exist(if it null then?) and issuetype = bug, set description to template
if (!descriptionValue && issueTypeValue == 10004){
descriptionField.setFormValue(templateValue)
}

if (descriptionValue != templateValue && issueTypeValue == 10004){
return
}

I hope code not ruined, on creating this question, parser noticed, that some content was replaced.

Main thing that i want, is: when description equal template and type not equal bug, description field cleared. If description not exists and type equal bug, description filling with template. Third case is when description is not null, but not equal template -> do nothing

I got stuck in one thing, if description contain some information, descriptionValue still "Null".

If i add some logging, i get:

[c.o.j.groovy.user.FieldBehaviours] descriptionValue null
[c.o.j.groovy.user.FieldBehaviours] descriptionValue1 null

I found in some examples two possible(i think) methods of getting value of form, but all of them return Null.  getValue works perfectly with all the fields, except description and summary. Maybe i'm doing something wrong.

So i have a question, how can i get current description on create issue screen, or i can only set it?

I need it not only to compare with template, but also to save content, for example if user started to create random issue, but later realise, that he's not setted issue type to bug, changing to bug, and all contents of description got cleared and filled with template, this is not a good thing.

2 answers

0 votes
Michael Kornatzki
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.
Dec 10, 2019

Hi JD,

did you resolve your problem?

I also can't get the value of the description field 

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 14, 2019

I think the issue is that at the time that the initializer runs, the form field for the description has not yet been populated by jira (which seems to keep it in memory and re-apply it to the field after the fields are rendered).

Put your code against the Issue Type field instead of the initializer, it will refresh each time you change the issue type.

It also runs when the form is first initialised because it runs when the issueType field is populated from the default.

But this won't work when you are using the standalone CreateIssue.jspa which shows project/issue type then open a new screen with all the fields. For that case, you will still need the initializer. But you'll have to be careful that they work well together.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events