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

Cole
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.
October 28, 2016

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

0 votes
Cole
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.
October 31, 2016

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.

0 votes
David _old account_
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.
October 31, 2016

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

0 votes
Cole
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.
October 31, 2016

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.

0 votes
Cole
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.
October 31, 2016

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.

0 votes
David _old account_
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.
October 31, 2016

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

0 votes
Cole
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.
October 31, 2016

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? 

0 votes
David _old account_
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.
October 31, 2016

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?

0 votes
Cole
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.
October 31, 2016

It is a select field with numbers as the options.

0 votes
David _old account_
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.
October 28, 2016

What is the field type of customfield_18370?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events