Hi, I have a problem, why is the scrypt that works on postfunction not working in automation for JIRA? Can someone explain why it doesn't work?
----CODE----
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import java.sql.Timestamp
def issueManager = ComponentAccessor.getIssueManager()
def cfDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12018") // date custom field
def cfCyklic = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12019") // select custom field
def dateFieldValue = issue.getCustomFieldValue(cfDate)
def cfCyklicValue = issue.getCustomFieldValue(cfCyklic)
def selectedOption = ((LazyLoadedOption)cfCyklicValue).getValue ()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser ()
def date = Calendar.getInstance()
if (selectedOption.equals ("miesięczna")){
// if miesięczna selected add 1 month
date.add(Calendar.MONTH, 1)
} else if (selectedOption.equals ("kwartalna")){
// if kwartalna selected add 2 month
date.add(Calendar.MONTH, 3)
} else if (selectedOption.equals ("półroczna")){
// if kwartalna selected add 2 month
date.add(Calendar.MONTH, 6)
} else if (selectedOption.equals ("roczna")){
// if kwartalna selected add 2 month
date.add(Calendar.MONTH, 12)
}
issue.setCustomFieldValue(cfDate, new Timestamp(date.getTimeInMillis()))
//sue.setCustomFieldValue(cfDate, Date.from(date.toInstant()))
//issue.setCustomFieldValue(cfDate, new Date(date.getTime()))
//issue.setCustomFieldValue(cfDate, date.toInstant())
//issue.setCustomFieldValue(cfDate, date )
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)