Hi Team,
I am trying to update a date field called "FTR" whenever another date field (FSD) is updated.
I am trying to do this using Automation for Jira (attached screenshot).
My script is as below
import com.atlassian.jira.component.ComponentAccessor
import java.util.Calendar
// Get the custom field manage
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// Retrieve the custom fields by name
def fsdField = customFieldManager.getCustomFieldObjectByName("FSD (First Service Date)")
def ftrField = customFieldManager.getCustomFieldObjectByName("First Training Release Date")
// Log if the fields are not found
if (fsdField == null) {
return "FSD (First Service Date) custom field not found."
}
if (ftrField == null) {
return "First Training Release Date custom field not found."
}
// Get the value of the FSD field (date)
def fsdDate = issue.getCustomFieldValue(fsdField)
// Ensure fsdDate is not null
if (fsdDate == null) {
return "FSD (First Service Date) field is empty or invalid."
}
// Log the original FSD date for debugging
log.info("Original FSD Date: " + fsdDate)
// Create a Calendar object to manipulate the date
def calendar = Calendar.getInstance()
calendar.setTime(fsdDate)
// Loop to subtract 28 business days (skip weekends)
int businessDaysToSubtract = 28
int subtractedDays = 0
while (subtractedDays < businessDaysToSubtract) {
calendar.add(Calendar.DAY_OF_MONTH, -1)
// Go back one day // Check if it's a business day (Monday to Friday)
if (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
subtractedDays++
}
}
// Get the new date after subtracting 28 business days
def newDate = calendar.getTime()
// Log the new date for debugging
log.info("New Date after subtracting 28 business days: " + newDate)
// Set the calculated date to the First Training Release Date field
issue.setCustomFieldValue(ftrField, newDate)
// Log success
log.info("Successfully updated First Training Release Date field to: " + newDate)
// Return success message
return "First Training Release Date successfully updated to: ${newDate}"
But it is not updating the FTR field.
Am i missing something here?