Problem:
I need the issue statistics or 2-dimensional statistic dashboard gadget to group by date. For our current need, the calendar gadget will not work.
Due to this, I'm trying a workaround where I copy the date from a date field and create a label. When I copy from the field, the problem is that it creates 3 labels; the date, the time (12-hour format), and AM/PM. I only want the date to be copied.
Is there a way on a post-function script that ScriptRunner could copy just the date to the custom label field?
Hi @Matt Noe you can use the java date routines in scriptrunner.
This example was used to trigger a script in a job that would publish a report to confluence from jira but it's a good example of using the date functions:
import java.text.SimpleDateFormat
import java.sql.Timestamp
import java.text.DateFormat
import java.util.Date
// retrieve details of the current date so that we can run at midnight first day of month against prior month
def cal = Calendar.instance;
def currentYear = cal.get(Calendar.YEAR);
def currentMonth = cal.get(Calendar.MONTH);
// set the month instance to the start of the previous month
if ( currentMonth == 0 ) {
cal.set(currentYear-1, 11, 1);
} else {
cal.set(currentYear, (currentMonth-1), 1); // comment this line to run the report mid-month for current month
//cal.set(currentYear, (currentMonth), 1); // uncomment this line run the report mid-month re:remove the -1 from (currentMonth-1)
}
// extract the date, and format it to a string
Date previousMonthStart = cal.time;
String previousMonthStartFormatted = previousMonthStart.format('yyyy-MM-dd');
String previousMonthStartFormattedwithName = previousMonthStart.format('MMM-yyyy');
def today = new Date().format('MMM-dd-yyyy'); //for mid-month report run
Here's anther example in the Scriptrunner library
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.