Trying to make one workflow to set a cascading field based on multiple other fields

I am not very proficient in groovy or java, so this is all rather new to me. I have tried to have others look over it, but they see no issues with it. It could just be something small. I guess I just need another set of eyes.


I have a workflow built, but it is not working fully. I cannot figure out a way to do it properly. Most of it works, however, the else is only half working. Basically if they choose anything other than 1,2,3, or null it does the main if thing, but if they do choose 1,2,3, or null it should use the else, but it is not currently. If I remove the "||" and everything with that it works fine, so it is obviously an issue there, I just cannot figure it out.

My logic:

If quantity > 3 OR pickup date - returned date > 14 set Support Group as Desktop - Move/Add/Change

Else set Support Group as Service Desk

My code:

import com.atlassian.jira.component.ComponentAccessor;
if ((issue.get("customfield_18370") != "1" && issue.get("customfield_18370") != "2" && issue.get("customfield_18370") != "3" && issue.get("customfield_18370") != null) || (((issue.get("customfield_18372").getTime() - issue.get("customfield_18371").getTime()) / 1000 / 3600 / 24) > 14)){
def optionsManager = ComponentAccessor.getOptionsManager();
def parentOptionObj = optionsManager.findByOptionId(18919);
def childOptionObj = optionsManager.findByOptionId(19047);
Map<String,Object> newValues = new HashMap<String, String>();
newValues.put(null, parentOptionObj);
newValues.put("1", childOptionObj);
return newValues;
def optionsManager = ComponentAccessor.getOptionsManager();
def parentOptionObj = optionsManager.findByOptionId(19044);
Map<String,Object> newValues = new HashMap<String, Object>();
newValues.put(null, parentOptionObj);
return newValues;

9 answers

What is the field type of customfield_18370?

It is a select field with numbers as the options.

In the logic you've implemented, you will get the else only if the user selects 1, 2 or 3 AND pickup date - returned date <= 14. Is that what you tested?

I was wanting it to run the else if the user selects 1, 2, or 3 OR pickup date - returned date <= 14. I had thought that's what my logic was because of the or in the if statement? If not, what do I need to change to make it reflect that? 

You need an AND, not an OR:

if (quantity &gt; 3 AND pickup date - returned date &gt; 14)
  set Support Group as Desktop - Move/Add/Change
  set Support Group as Service Desk

because (according to your latest response), if pickup date - returned date <= 14, you want to hit the "else" regardless of the quantity. So the first case is only when pickup date - returned date > 14 and quantity > 3

Thanks for the response. I see I misspoke previously. I think this issue might be due to leaving the date null in testing. I thought that would be covered in the else though. If I add the date != null in the else, or make it an else if rather, it should work I think.

The below is just to clarify where I previously misspoke.

So I still want the first case to occur if quantity is > 3 OR  pickup date - returned date > 14

Then the else for if quantity is <= 3 OR pickup date - returned date <= 14

I tried doing separate post functions, but the order of them overwrites the result, which is not my intention. I guess I could try doing a series of else if statements? I just thought my current way would do all that I wanted since I have the or.

My thinking was it would see if the quantity was > 3. If so, set the result, if not, move on to see if the dates is > 14. If so, set the result, if not, move to the else. I would only want to trigger the else if both of the above are false.

A smarter thing for me I think is to just make the pickup date and return date fields required. Thanks for your help, David. Turns out I just wasn't thinking correctly.

And which combination of quantity and duration is not currently working the way you expect?

It is just when you select a quantity < 3, but leave the the dates blank that was causing an issue. I had a clause in there for if the quantity was null, but not the dates.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


203 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you