How to hide field from transition screen and from specific workflow using script runner

Jyoti Kumari July 5, 2023

Hello Everyone,

 

I wanted to know, how we can hide field from transition screen and from specific workflow using script runner.

Thanks and Regards,

Jyoti

3 answers

2 votes
Evgenii
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.
July 5, 2023

Hi, @Jyoti Kumari 

1. Go to ScriptRunner -> Behavior

2. Add new Behavior

3. Add mapping (for what project and issuetype it must work)

4. Select required workflow

5. Select field, you want to hide

6. Turn trigger Shown to Hidden

7. Add condition, when it must happen. For this - press Add condition, then select Workflow action, and select required transition

image.png

Jyoti Kumari July 6, 2023

Thanks for this example, but I want to hide this custom field from the transition screen for closed workflow state from some projects and want to unhide it from specific project, which is using same transition screen. 

Evgenii
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.
July 11, 2023

Hi, @Jyoti Kumari 

If it's for different workflows, I'm affraid it can't be made in one behaviour. You'll have to make 2+ behaviours.

If some projects share one workflow, you can make one behaviour for them, and configure correct mapping, select there required projects.

2 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 5, 2023

Hello @Jyoti Kumari 

Can you provide more information about the problem you are trying to solve by hiding the field? Why can you not simply remove the field from the Transition screen and from the Issue screens?

Jyoti Kumari July 6, 2023

I need one custom field to be added automatically on closed workflow state ,as it is mandatory for single project.This field is not require in any other projects transition screen.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 10, 2023

I recommend that you create a separate transition screen and workflow for that one project.

Like Evgenii likes this
Evgenii
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.
July 10, 2023

Great idea. And I think, it can be combined with Conditions, which transition to show. 

Jyoti Kumari July 10, 2023

Hello Evgeniy and Trudy Claspill,

 

We are avoiding to create multiple workflows and transition screen, bcoz these can be applied for multiple projects, if handled  through script runner.Is it possible to hide specific fields on specific transition screen, if screen matched.

Best Regards,

Jyoti 

1 vote
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.
July 17, 2023

Hi @Jyoti Kumari

To answer your question, this is very much doable via ScriptRunner's Behaviour.

However, you will need to create one custom screen. This custom screen can be reused for any of your transitions.

Below is a screenshot of the sample screen that I have created.

1. Create a new screen. I have added a new screen called MOCK: Sample in the screenshot below.

screen1.png

2. I have added 3 custom fields to this screen, i.e. Sample Checkbox, Sample Cascade and Sample List.

screen2.png

Once the field has been created, associate it with whichever transition you want to use it in. For this example, I have associated this screen with two transitions, the In Progress transition and the QA transition, as shown in the screenshots below:-

1. For the In Progress transition:-

config2.png

2. For the QA transition:-

config3.png

 

Next, you will need to create a Behaviour Initialiser. Below is the sample working code that I have tested with:-

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

@BaseScript FieldBehaviours behaviours
def sampleCascade = getFieldByName('Sample Cascade')
def sampleList = getFieldByName('Sample List')

sampleCascade.hidden = false
sampleList.hidden = false

if (actionName == 'In Progress') {
sampleList.hidden = true
sampleCascade.hidden = true
}

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

As shown in the sample code above, you must use the actionName variable to identify which transition screen(s) you want the Behaviour to take effect.

In the sample code above, when the transition screen is used for only the In Progress transition, the Sample Casde and Sample List fields will be hidden. These fields will be visible in all other transitions.

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

Below are a couple of test screenshots for your reference:-

1. I am going to transition the screen to In Progress. 

test1.png

2. As expected, the Behaviour has taken effect and hidden the Sample List and Sample Cascade fields. Only the Sample Checkbox field is visible, as shown in the screenshot below:-

test2.png

3. Next, I will transition the issue to the QA status.

test3.png

4. As expected, all the fields, i.e. Sample Checkbox, Sample Cascade and Sample List, are visible in the transition screen as shown in the screenshot below:-

test4.png

The same rule applies if you intend to use this for Multiple Workflows. You can reuse that one custom screen created, associate it with the transitions you want o use and add the correct actionName to filter it.

You must also ensure the projects you are using are associated with your Behaviour.

In the updated sample code below, I have added the list of work with 2 different workflows, i.e. for two different projects.

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

@BaseScript FieldBehaviours behaviours
def sampleCascade = getFieldByName('Sample Cascade')
def sampleList = getFieldByName('Sample List')

sampleCascade.hidden = false
sampleList.hidden = false

log
.warn "======>>> ${actionName}"

if (actionName == 'In Progress') {
sampleList.hidden = true
sampleCascade.hidden = true
} else if (actionName == 'Back to open') {
sampleCascade.hidden = true
}

The first actionName is for the MOCK project in the example above, and the 'Back to Open' is for the Service Test project, i.e. a Service Desk project.

Below is the Behaviour configuration now with two projects associated with it:-

behaviour_config2.png

Below is a screenshot of the Service Test project's workflow:-

config4.png

 

Below are a couple of test screenshots when testing with the Service Test project.

1. Transitoin the issue from Pending to Back to open

test5.png

2. As expected, the transition screen appears, and the Sample Cascade list is hidden per the updated Behaviour code.

test6.png

An additional note, in the updated sample code, I've also included a log parameter. This is to identify the actionName that is used in the transition.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Jyoti Kumari July 17, 2023

Hello Ram Kumar Aravindakshan,

 

Thank you so much for such detailed explanation, but my concern is how we can restrict this behaviour for specific transition screen, for ex- 'Mock' transition screen, which is  mentioned in your example, as 'In-progress' Workflow state might available in multiple screen, so the above behaviour might work for create and edit screen also, if same field exist there.Can you give example, how we can apply this behaviour on Mock Transition screen.   

Thanks and Regards,

Jyoti

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.
July 25, 2023

Hi @Jyoti Kumari

In your last comment, you mentioned:-

Thank you so much for such detailed explanation, but my concern is how we can restrict this behaviour for specific transition screen, for ex- 'Mock' transition screen, which is  mentioned in your example, as 'In-progress' Workflow state might available in multiple screen, 

Firstly, you cannot add more than one screen to a transition. Each transition is only able to add one screen. You have to be clear about this.

The example I provided is using the Mock Transition screen on Multiple Transitions.

The transition screen's name will change dynamically depending on your transition.

For example, if I add the Mock Transition screen to the In Progress transition, the actionName will change to In Progress. If it is added to the Done transition, the actionName will change to Done and so on.

Hence, you must set the condition according to the actionName, as I have shown in my previous comment.

In regards to additional filtration, for example, if you want the In Progress transition for a particular project, the if condition can be modified to something like:-

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

@BaseScript FieldBehaviours behaviours
def sampleCascade = getFieldByName('Sample Cascade')
def sampleList = getFieldByName('Sample List')

sampleCascade.hidden = false
sampleList.hidden = false

def project = issueContext.projectObject

log.warn "======>>> ${actionName}"

if (project.key == 'MOCK') {
if (actionName == 'In Progress') {
sampleList.hidden = true
sampleCascade.hidden = true
} else if (actionName == 'Back to open') {
sampleCascade.hidden = true
}
} else if (project.key == 'ST') {
if (actionName == 'Done') {
sampleList.hidden = true
}
}

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

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

rajeswari saravanan April 9, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

Im looking to the similar issue,

I have one query, for eg,

If issue is created based on one select list, I need the field to be populated on selection of option in select list field (when its created)

I have updated the fields in the screen which needs to be populated

and also created a behaviour with condition that

if request type = xx (when creation)it should display the category field in the transition. If not category field should be hidden. ( with condition as when workflow step: Resolved)

But this is not working as expected. Do I need any changes to be done for this

Suggest an answer

Log in or Sign up to answer