Forums

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

Behaviours: Write an hardcoded description

Dan27
Contributor
June 20, 2018

Hello,

I write a behaviour that set default description data while creating "Bug-Internal" and "Sub-Bug" types (By Map). 

It worked ok, But also all other types set this description..

How can I clear this in other types? I try with a condition but it still worked on all types.

 

this is my code:

def desc = getFieldById("description")
//def issueType = getFieldById("issuetype")

def defaultValue = """h3. General OS / DB / Browser / Machine Information:
====================================


h3. Scenario Description and steps to recreate the problem:
====================================


**

h3. Actual & Expected Results
====================================

**

**

h3. Log file information:
====================================

 

h3. Additional info (Optional):
==================================== """

if ((issueContext.issueType.name !="Bug-Internal") && (issueContext.issueType.name !="Sub-Bug")){
desc.setFormValue("")
}
else {
desc.setFormValue(defaultValue)
}

2 answers

0 votes
Mark Markov
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.
June 20, 2018

Hello @Dan27

Where are you place your code? I check it and it works pretty well.

You need to map it to issuetype field

image.png

Dan27
Contributor
June 20, 2018

hi @Mark Markov

Where did you write this line ??

I write my code inside 'fields' in the Behaviours

Mark Markov
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.
June 20, 2018

Here example for last version of scriptrunnerСнимок экрана 2018-06-20 в 17.10.30.png

Dan27
Contributor
June 20, 2018

Unfortunately, My Behaviours looks different..  

I wrote my code inside Filters, and I chose Bug-Internal and Sub-Bug in Map.

Mark Markov
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.
June 21, 2018

Can your provide screenshot of your configuration?

You need to create behaviour like this

1) Add-ons -> Behaviours -> Add

2) Add mapping to your project and all issue types

3) Fields -> Add "Issue Type" field

4) On added field add serverside script and place your code here

0 votes
Marcos Sanchez
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.
June 20, 2018

Hi Daniel,

As I understand, you are setting the behaviour with a mapping that affects only Bug-Internal and Sub-Bug issuetypes and then, inside your code, you are setting the description field based on the issuetype (again).

That's the problem, let me explain myself:

As far as you set the mapping for only Bug-Internal and Sub-Bug, when you choose one of these issuetypes the field will be set correctly because it triggers the behaviour, but when you change to another issuetype they will not use the behaviour as you didn't set them on the mapping.

So, this part of the code if ((issueContext.issueType.name !="Bug-Internal") && (issueContext.issueType.name !="Sub-Bug")) is redundant with the mapping and will not be used when you choose a different issuetype.

I'm not sure of which is the very best way to do this, but if you don't specify the issuetype on the mapping (only specify the project(s)) it should work with your current code.

Hope it helps.

 

Regards,
Marcos

Dan27
Contributor
June 20, 2018

@Marcos Sanchez I didn't understand.. Remove the Map (Choose all types) and leave the condition inside the code ?

Marcos Sanchez
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.
June 20, 2018

Hi,

Yes, choose all types (but defining the project, of course).

As I said, maybe there could be better ways to do this, but I'm not sure of which ways are...

 

Regards,

Marcos

Dan27
Contributor
June 20, 2018

it's still not working...

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events