Change status if datepicker = current date?

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.

1 answer

1 accepted

1 vote
Accepted answer

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.

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

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

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)

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);

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.

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!

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? smile [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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,155 views 0 8
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