I'm trying to do some workflows, but I am not sure exactly how to accomplish some of it. I have a datepicker field called pickup date and I want it so that if the user selects today's date that it will change the status to escalated. I was hoping to use the transition issue post function to do this, but am unsure what to put in the groovy expression.
That's the right approach. In the condition, you can probably do something like:
if (issue.get("<your datepicker field>")==null) return false; Calendar pickupDate = Calendar.getInstance(); pickupDate.setTime(issue.get("<your datepicker field>")); Calendar cal = Calendar.getInstance(); //reset to 0:00 cal.set(Calendar.HOUR_OF_DAY, 0); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); return pickupDate.compareTo(cal) >=0; //returns true if pickupDate >= start of today.
Got it working! Thank you very much!
Had some issues at first, but I moved the post function to happen after the issue created event.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Another workflow I am trying to do might be similar as it involves dates... Not sure if you can help me with that.
If pickup date - returned date > 14 set custom cascading field as as Desktop Move/Add/Change
This was my thinking, but it did not really work:
import com.atlassian.jira.component.ComponentAccessor; if ((issue.get("customfield_18872") - (customfield_18873)) > 14) { def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(19472); def childOptionObj = optionsManager.findByOptionId(19488); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put(null, parentOptionObj); newValues.put("1", childOptionObj); return newValues; }
Or maybe something like this?
import com.atlassian.jira.component.ComponentAccessor; date sDate = (issue.get("customfield_18872") date eDate =(issue.get("customfield_18873") number diffTime=0; while(sDate<eDate){ sDate=sDate+"1h"; diffTime=diffTime+1; } return true; if(diffTime>14){ def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(19472); def childOptionObj = optionsManager.findByOptionId(19488); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put(null, parentOptionObj); newValues.put("1", childOptionObj); return newValues; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am also seeing that the original code you posted is not working correctly on my end as I thought. Any date after today's date makes the status change as well...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Cole,
both your code snippets have obvious programming errors. Please have them checked by a Java/Groovy developer.
As for my snippet, I thought that was what you wanted. If not, then you should also reset the pickupDate to 0:00 and then compare for equality (== 0 instead of >= 0)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey David,
Thank you very much for your help. I do not have a Java/Groovy developer to look it over, but I will try to find a resource to look over my code. Sorry, I am a beginner with this type of stuff.
I also apologize if I was not clear with what I was trying to achieve. I just want it so that if the pickup date is today, not after, that it moves to an escalated status. As for the resetting pickupDate, what is the best way to do this? I've tried a variety of ways, but cannot seem to get it working. Again, I am a beginner, so I am not sure what I am doing with this stuff really.
Based on your above code I thought it would be something like adding this:
pickupDate.set(Calendar.YEAR, 0); pickupDate.set(Calendar.MONTH, 0); pickupDate.set(Calendar.DAY_OF_MONTH, 0);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, you'd do the same as for "cal":
if (issue.get("<your datepicker field>")==null) return false; Calendar pickupDate = Calendar.getInstance(); pickupDate.setTime(issue.get("<your datepicker field>")); Calendar cal = Calendar.getInstance(); //reset to 0:00 cal.set(Calendar.HOUR_OF_DAY, 0); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); pickupDate.set(Calendar.HOUR_OF_DAY, 0); pickupDate.clear(Calendar.MINUTE); pickupDate.clear(Calendar.SECOND); pickupDate.clear(Calendar.MILLISECOND); return pickupDate.compareTo(cal) ==0; //returns true if start of pickupDate == start of today.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
David,
This is now working! Thank you so much. You sir are a wizard. I really appreciate all your help! Now I just have one more workflow to solve! Have a great day!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to be of service.
If you are happy with our product and our support, why not leave a quick review for us in the marketplace? [This link| https://marketplace.atlassian.com/plugins/com.innovalog.jmwe.jira-misc-workflow-extensions/cloud/reviews] will take you directly to the reviews page.
Much appreciated!
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.