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

Scriptrunner: Add a Condition to a Web Section Limiting Issue Type

Michael Thompson
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 17, 2019

Having some trouble with Script Fragments in Jira Software 8.1.0. and Adaptavist ScriptRunner 5.5.6.1-jira8.

GOAL

One of my projects contains a unique Issue Type called AWS Migrations. We create a parent issue and six sub-tasks underneath it for each software environment (QA, Pre-Prod, Practice, Production, and Demo).

I want to replace the Clone button with multiple scripts to Clone to P_PRE, Clone to P_PS, Clone to P_PRD, and Clone to P_DEM. This will allow me to create a custom clone script that also edits certain values in the master ticket that are important for each environment.

PROBLEM

My first script fragment should hide the Clone option from the More dropdown, but only if the Issue Type is AWS Migrations. I added the following condition and it works fine.

! (issue.issueType.name == "AWS Migration")

My next script fragment is to add a new option Clone to P_PRE to the More dropdown. Since this should only be available if Issue Type is AWS Migrations, I figured this should work.

issue.issueType.name == "AWS Migration"

Instead, I get the following checking error:

[Static type checking] - The variable [issue] is undeclared.
@ line 1, column 1.

QUESTION

Why is this happening? What is the correct syntax for the condition?

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Ilya Turov
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, 2019

try using jiraHelper.contextParams.issue.issueType.name instead

Michael Thompson
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, 2019

No love with that one either.

jiraHelper.contextParams.issue.issueType.name == "AWS Migration"

[Static type checking] - The variable [jiraHelper] is undeclared.
Ilya Turov
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, 2019

did you actually try to save it and see if it works? because i tried logging it and it was fine. dont let simple type checking errors stop you.

i feel like even your original condition might be working. 

Michael Thompson
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, 2019

That's odd, I replied about an hour ago and it's not here.

At any rate, I enabled both fragments and I successfully hid the original Clone option, but the new "Clone to P_PRE" option is missing.

missingNewClone.jpg

Ilya Turov
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, 2019

I think you are mistaking web section and web item

web section is basically what it is - a section (like how you see "create sub-task" button in your example is separated from top and bottom elements - that's because it'l located into it's personal section)

So I'd refer to examples here:

https://scriptrunner.adaptavist.com/5.5.0/jira/fragments/WebItem.html

Like • Michael Thompson likes this
Michael Thompson
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 25, 2019

You're absolutely right, that is what I was doing wrong. I changed the fragment to a Web item and the "Clone to P_PRE" option appears in the drop down. Thanks Ilya!

I can't accept your reply as the answer, so I will accept the message thread. :)

0 votes
PD Sheehan
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, 2019

The web section is just a placeholder for the web items to go into.

So set your section to always be visible. It should only display when you have a visible web items in it.

And the web item has the issue as an available binding.

0 votes
Ilya Turov
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 17, 2019

I guess different types of fragments have different types of Binding Variables.

What kind of fragment are you using in the second case? Also, there's a (?) question mark button in the bottom right corner which shows which variables you can use without declaring to help you.

Michael Thompson
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, 2019

Hi Ilya,

In the second case, I am using "Create a custom web section".

I did click on the question mark, but the resulting information wasn't particularly useful (see screenshot). Nothing clickable, just a vague commentary.

fragmentHelp.jpg

TAGS
AUG Leaders

Atlassian Community Events