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

Scriptrunner: how to identify an issue type as both a Parent and Child

Edited
Diana
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.
Feb 03, 2022

I have an issue type called Spikes. These Spikes can be linked at the parent level (derivation is) and as a child (is derived from).

 I have 3 custom fields A, B, and C. With custom field A always showing on the issue screen.

If Spike is a parent, and custom field A is checked Yes, then custom field B and C appears.
If Spike is a parent, and custom field A is unchecked, then B and C clears and disappears.

If Spike is a child, and custom field A is checked, then custom field C appears.
If Spike is a child, and custom field A is unchecked, then C clears and disappears.

I'm at a lost when it comes to script writing, but is it possible for write a script that can identify an issue both at a parent and child level as well as make the script run different instructions based on what level an issue is?

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Feb 11, 2022 • edited

Hi @Diana Gorv

I have doubt to clarify with you, i.e. what type of fields are you using for A, B and C? Are they checkboxes or radio buttons?

Below is an example working code that can be used for either radio buttons or checked boxes.

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def optionsA = getFieldById(fieldChanged)
def optionsB = getFieldByName('Options B')
def optionsC = getFieldByName('Options C')

def optionsAValue = optionsA.value.toString()
optionsB.hidden = true
optionsC.hidden = true

if (optionsAValue == 'Yes') {
if (issueContext.issueType.name != 'Sub-task') {
optionsB.hidden = false
optionsC.hidden = false
} else {
optionsC.hidden = false
}
}

Please note the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

In this sample code, if the issue type is Bug, Task or Story, when Options A is set to Yes, the fields Options B and Options C will be visible.

And if it is a Sub-task issue type, when Options A is set to Yes, only the field Options C will be visible.

You will need to change the code according to your environment, i.e., the Parent issue type and the child issue type.

Below is a print screen of the Behaviour configuration:-

behaviour_config.png

 

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram

Diana
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.
Feb 14, 2022

Thank you @Ram Kumar Aravindakshan _Adaptavist_ I'll use this code.

Custom field A is a checkbox while custom field B and C are dropdown menus. But I think I understand what I need to do from this example. 

Thanks again!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events