Hi,
On the Create screen "when should it be restored?" I have a field called I have 1 week, 2 week and 1 month options in this field.
I also have a field called "End Date" on the View screen.
When I select the '1 week' option on the Create screen, I want the date in the 'End Date' field to be automatically set one week after the date I created the record, two weeks when I select the '2 week' option, and one month later when I select the '1 month' option.
The script below works correctly for the 1 week and 2 week options but incorrectly for the 1 month option.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.CustomFieldType
import java.sql.Timestamp;
import com.atlassian.jira.event.type.EventDispatchOption
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
import java.sql.Timestamp
import java.text.SimpleDateFormat
import java.time.LocalDate
def issueManager = ComponentAccessor.getIssueManager()
//def issue = issueManager.getIssueObject("DEMO-48")
def mutableIssue = (MutableIssue) issue
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def user = authenticationContext.getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def Calendar cal = Calendar.getInstance();
def endDateCF = customFieldManager.getCustomFieldObject("customfield_11334")
def whenShouldRestoreCF = customFieldManager.getCustomFieldObject("customfield_11335")
def fieldConfig = whenShouldRestoreCF.getRelevantConfig(issue)
def option1 = optionsManager.getOptions(fieldConfig).find {it.value == "1 week"}
def option2 = optionsManager.getOptions(fieldConfig).find {it.value == "2 week"}
def option3 = optionsManager.getOptions(fieldConfig).find {it.value == "3 week"}
if( issue.getCustomFieldValue(whenShouldRestoreCF) == option1){
def newUpdate = new Timestamp(cal.getTimeInMillis()+ 7*1000*24*60*60);
mutableIssue.setCustomFieldValue(endDateCF, newUpdate)
}
if( issue.getCustomFieldValue(whenShouldRestoreCF) == option2 ){
def newUpdate = new Timestamp(cal.getTimeInMillis()+ 14*1000*24*60*60);
mutableIssue.setCustomFieldValue(endDateCF, newUpdate)
}
if( issue.getCustomFieldValue(whenShouldRestoreCF) == option3 ){
LocalDate futureDate = LocalDate.now().plusMonths(1);
def newUpdate = futureDate
mutableIssue.setCustomFieldValue(endDateCF, newUpdate)
}
issueManager.updateIssue(user, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
//return issue.getDueDate()
What is the problem, how can I edit it?
Thanks for your help,
Have a nice day 