Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set "select type" custom field value based on value of another "select type" custom field?

Using the "Set field value (JMWE app)" post function I need to set the value of a custom field based on the values of another.

Custom Field 1: "Grant Type" (A,B,C)
Custom Field 2: "Team Queue" (1,2,3,4,5)


If "Grant Type" selectedValue = A set "Team Queue" selectedValue to 5
If "Grant Type" selectedValue = B set "Team Queue" selectedValue to 4
If "Grant Type" selectedValue = C set "Team Queue" selectedValue to 2...

 

What is the proper syntax for this? I am struggling with it...

2 answers

2 accepted

2 votes
Answer accepted

Hi @Pete P 

using JMWE's Set Field Value post-function, you can easily achieve this.

As the "Field to set", select your Team Queue field.

As the Value type, select "Groovy Expression"

As the Value, use a script like:

switch (issue.get("Grant Type")) {
case "A": return 5;
case "B": return 4;
case "C": return 2;
}

This assumes that the Team Queue field is a Number field. Otherwise, you'll need to return a String instead:

switch (issue.get("Grant Type")) {
case "A": return "5";
case "B": return "4";
case "C": return "2";
}

Thank you @David Fischer _Appfire_  - works as described :)

@David Fischer _Appfire_  - one more question if I may ask. 
Above works perfectly for my single select lists. 

Do you know syntax to use for determining the "case" value with custom field type "Select List (cascading)" ?  

In this field type there is parent option and selected value.  If I just use selected value for case it doesn't work, also I tried "parent option - selected value" which also does not work.  

Hi @Pete P ,

well, it depends on how you want to treat the parent and child options. Do you have a different Team Queue value for each combination of parent and child values? Or is it based just on the parent value?

If it's based on the combination of parent and child, you can do something like:

switch (issue.get("customfield_10202")?.get(null)?.value) {
case "Parent A":
switch (issue.get("customfield_10202")?.get("1")?.value) {
case "Child 1": return "A.1"
 case "Child 2": return "A.2"
}
  case "Parent B":
switch (issue.get("customfield_10202")?.get("1")?.value) {
case "Child 1": return "B.1"
  case "Child 2": return "B.2"
}
}

If neither the parent nor the child values can contain a comma (","), then you can also use a single switch, knowing that the parent value and child value will be separated with a comma:

switch (issue.getAsString("customfield_10202")) {
case "Parent A,Child 1": return "A-1"
 case "Parent A,Child 2": return "A-2"
 case "Parent B,Child 1": return "B-1"
//etc...
}

@David Fischer _Appfire_  thanks very much for your time and efforts!

The second method worked for my needs fortunately 😁

0 votes
Answer accepted
Fabian Lim Community Leader Dec 30, 2021

Hi @Pete P

I believe the "Set field value" post-function has a lot of limitations.  Use the "Scripted Groovy" post function instead.

You can follow the instructions here for the scripted groovy post function: https://innovalog.atlassian.net/wiki/spaces/JMWE/pages/139635057/Scripted+Groovy+operation+on+issue

Regards

Thanks for advice @Fabian Lim 

They are pretty vague on their examples unfortunately

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.2
TAGS
Community showcase
Published in Jira

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

113 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you