Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Custom date field (Action Due date) needs to update the custom text field(Action due week)e.g. 16W07

I am already having the same function with Fields Due date and Release Week

If I update due date with 2019-03-08 the Release Week updates as 1910:5

Same requirement I need with Custom date field (Action Due date) needs to update the custom text field(Action due week)e.g. 16W07

Here we are using the custom script:

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import java.sql.Timestamp;
//import java.util.calendar.*;
//import java.text.SimpleDateFormat;
if(issue.getProjectObject() != null)
if(issue.getProjectObject().getId() != 11016)
{//Update ReleaseWeek with week Except for WH-PCR Project
Date date = issue.getDueDate();
String relYearWeek = "";
Calendar calUK = Calendar.getInstance(Locale.UK);
//Calendar calUS = Calendar.getInstance(Locale.US);
//if(date != null)
if(date)
{
calUK.setTime(date);
// calUS.setTime(date);

String dueDateYearUK = calUK.getWeekYear().toString().substring(2);
String dueDateWeekUK = calUK.get(Calendar.WEEK_OF_YEAR).toString();
String dueDateDayOfWeekUK = calUK.get(Calendar.DAY_OF_WEEK).toString();
String dayOfWeek = "";
if(calUK.get(Calendar.DAY_OF_WEEK)==Calendar.MONDAY)
dayOfWeek = ":1";
else if(calUK.get(Calendar.DAY_OF_WEEK)==Calendar.TUESDAY)
dayOfWeek = ":2";
else if(calUK.get(Calendar.DAY_OF_WEEK)==Calendar.WEDNESDAY)
dayOfWeek = ":3";
else if(calUK.get(Calendar.DAY_OF_WEEK)==Calendar.THURSDAY)
dayOfWeek = ":4";
else if(calUK.get(Calendar.DAY_OF_WEEK)==Calendar.FRIDAY)
dayOfWeek = ":5";
else if(calUK.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY)
dayOfWeek = ":6";
else if(calUK.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)
dayOfWeek = ":7";

//relYearWeek = calUK.getWeekYear().toString().substring(2) + dueDateWeekUK.padLeft(2, "0") + ":" +;
relYearWeek = dueDateYearUK + dueDateWeekUK.padLeft(2, "0") + dayOfWeek;//":" + dueDateDayOfWeekUK;

// String dueDateWeekUS = calUS.get(Calendar.WEEK_OF_YEAR).toString();
// String relYearWeekUS = calUS.getWeekYear().toString().substring(2) + dueDateWeekUS.padLeft(2, "0");
// return "EU:" + relYearWeek + ", US:" + relYearWeekUS;
// relYearWeek = "EU:" + relYearWeek + ", US:" + relYearWeekUS;
}
def cfManager = ComponentAccessor.getCustomFieldManager();
def relWeek = cfManager.getCustomFieldObjectByName("Release Week");
if(relYearWeek != "" || (relYearWeek == "" && issue.getCustomFieldValue(relWeek).toString() != ""))
relWeek.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(relWeek), relYearWeek), new DefaultIssueChangeHolder());
}

 

If I am replacing the Date date = issue.getDueDate(); with Action Due Date I am getting an error

Script.PNG

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

78 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you