Change status if datepicker = current date?

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 18, 2016

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
Answer accepted
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 18, 2016

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.
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 18, 2016

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.

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 18, 2016

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;
}
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 18, 2016

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

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 18, 2016

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)

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 19, 2016

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);
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 19, 2016

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.
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 20, 2016

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!

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 20, 2016

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
TAGS
AUG Leaders

Atlassian Community Events