Forums

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

How to update custom field value depending on the workflow status

Lakshmi
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.
December 11, 2023

Hi Team,

We have a requirement to change the custom field values in the dropdown depending on the workflow status.

For example :

 

We have a field "Test Dropdown", and The whole dropdown has values A,B,C,D,E,F
If the ticket is in the status, "In Progress", the dropdown should display A, D,E
If the ticket is in the status, "Review", dropdown should display B,C, F
etc
etc
The field should be editable on the form or transition screen, with values listed based on status.

3 answers

1 accepted

2 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.
December 13, 2023

Hi @Lakshmi S

Could you please clarify if you are using a Transition screen? I am asking this because if you intend to filter the  List's option, this can only be done using ScriptRunner's Behaviour.

However, a transition screen will be required if you want the filtration to occur according to the transition type.

You can use the Behaviour Initialiser to trigger the filtration. 

Below is a sample working code for your reference:-

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

@BaseScript FieldBehaviours behaviours
def sampleList = getFieldByName('Sample List')
def options = []

if (actionName == 'In Progress') {
options = ['Option1', 'Option2']
} else if (actionName == 'Done') {
options = ['Option3', 'Option4']
}

sampleList.setFieldOptions(options)

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

Below is a screenshot of the Behaviour configuration for your reference:-

behaviour_config.png

You will need to add the Transition screens to your Workflow accordingly and ensure the list is included in it.

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

Thank you and Kind regards,

Ram

Lakshmi
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.
December 13, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_Thank you for your quick response. The script works, and the field options are displayed on a particular transition based on the filter (I added a transition screen). Still, when creating the ticket, the field does not show any value; when editing the field in that particular status, the field does not show any value. Please find the attached screenshot for your reference.

The script is :

script1.png

 

Field on Create and edit the field to other value on particular status. 

On Create, It should display all values.

On Edit, It should display the filtered values only if the ticket is in that particular status.

Is it possible. Could please suggest me?

script2.png

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.
December 13, 2023

Hi @Lakshmi S

I'm not sure why it's not working on your side; it's working fine on mine.

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

1. When transitioning to the In Progress status, the options in the Sample List field are filtered to Option1 and Option2 and shown in the screenshot below:-

test1.jpg

 

2. When transitioning to the Done status, the options in the Sample List field are filtered to Option3 and Option4.test2.jpg

Please try to disable all your third-party plugins except for ScriptRunner and try to rerun the test. I am suggesting this because, in my environment, I am only using the ScriptRunner plugin to rule out if there are any conflicts with the plugins resulting in the problem you are encountering.

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

Lakshmi
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.
December 14, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

 No, This piece is perfectly working on the status transitions (I added them to the transition screen). 

 What I am asking is, 

Field on Create and edit ,

On Create, It should display all values, but it is showing "None" (as per my screenshot above) while creating the new ticket.

On Edit, It should display the filtered values only if the ticket is in that particular status (in Progress or Done), but it is showing "None" (as per my screenshot).

I was able to display all custom field values on "Create", but when we are editing the field, its still showing "None" instead of the filter values.

script3.png

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.
December 14, 2023

Hi @Lakshmi S

Sorry, I misread your last comment.

So, for your case, if you want to display all the options on the Create and Edit screen and filter the options on the Transition screens, you will need to update the def options = [] declaration and include all the options in it.

Below is the updated code for your reference:-

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

@BaseScript FieldBehaviours behaviours
def sampleList = getFieldByName('Sample List')
def options = ['Option1', 'Option2', 'Option3', 'Option4'] //Add all options in the List

if (actionName == 'In Progress') {
options = ['Option1', 'Option2']
} else if (actionName == 'Done') {
options = ['Option3', 'Option4']
}

sampleList.setFieldOptions(options)

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

Below is a screenshot of the updated Behaviour configuration:-

updated_behaviour_config.png

Once again, below are the test screenshots for your reference:-

1. If you observe the Create and Edit screens below, you will notice that all the options are available in the List.

create_screen.jpg

edit_screen.jpg

2. Accordingly, in the In Progress transition screen, the list is filtered only to display Option1 and Option2 as shown in the screenshot below:-

test1.jpg

3. Finally, in the Done screen, the list is filtered only to show Option3 and Option4.

test2.jpg

 

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

Thank you and Kind regards,

Ram

Lakshmi
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.
December 15, 2023

Its working expected. Thank you Ram! @Ram Kumar Aravindakshan _Adaptavist_ , You are the best! 

Is it possible ?

Will the shortened list show up in the edit also when in that particular status instead of all values?

For example : We are in the "In Progress" status, user wants to edit that field values in that "In Progress" status, it should display those filtered values only instead all custom field values.

2 votes
Dhiren Notani_Exalate_
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.
December 12, 2023

Hi @Lakshmi S ,

Thanks for posting your question here!

It's easy, just try out Jira Automation for this or you can even use Post function in Jira.

Simply add a rule like this : 

When: Issue transitioned
FROM
Backlog
TO
Selected for Development
Then: Edit issue fields
Labels
Alternative, please find some doc on Post Function which can also help here!
Thanks, Dhiren
0 votes
Mohanraj Thangamuthu
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 11, 2023

Hello, Good day. Jira don't have this option builtin. You can explore addons like script runner. https://community.atlassian.com/t5/Jira-Software-questions/How-to-show-custom-field-in-specific-statuses-only-hide-the-rest/qaq-p/1816591

Lakshmi
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.
December 12, 2023

Hello @Mohanraj Thangamuthu ,

 That's not my requirement. I want to update custom field values based on status.

Mohanraj Thangamuthu
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 12, 2023

You can explore the automation rule to change the field value based on issue status.

Suggest an answer

Log in or Sign up to answer