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;
}
else{
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

This widget could not be displayed.

What is the field type of customfield_18370?

This widget could not be displayed.

It is a select field with numbers as the options.

This widget could not be displayed.

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?

This widget could not be displayed.

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? 

This widget could not be displayed.

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
else
  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

This widget could not be displayed.

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.

This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

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 Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

510 views 3 18
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