Description
I'm trying to run a simple script in post-function, and it seem seems to be running, but I'm not getting the field value updated. Am I missing something somewhere?
--------
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userUtil = ComponentAccessor.getUserUtil()
def cfSeverity = customFieldManager.getCustomFieldObjectsByName("Severity")
def cfSeverityValue = issue.getCustomFieldValue(cfSeverity).toString()
int DueInDays = 0
log.warn ("Severity Value: "+ cfSeverityValue )
// Days in the future when the issue is due
switch (cfSeverityValue) {
case "Critical" : DueInDays = 30; break;
case "Major" : DueInDays = 60; break;
case "Moderate" : case "Minor" : DueInDays = 120; break;
default : DueInDays = 120; break;
}
// Make sure the due date doesn't fall on a weekend
Date today = new Date();
Calendar MyDueDate = Calendar.getInstance();
MyDueDate.add(Calendar.DATE,DueInDays)
while ([Calendar.SATURDAY, Calendar.SUNDAY].contains(MyDueDate.get(Calendar.DAY_OF_WEEK))) {
MyDueDate.add(Calendar.DATE,1)
}
def dueTimestamp = new Timestamp(MyDueDate.getTimeInMillis())
issue.setDueDate(dueTimestamp)
log.warn ("SetDueDate:" + dueTimestamp)
----------
Workflow
Creates the issue originally.
Custom script post-function - Set Due Date based on Severity
Re-index an issue to keep indexes in sync with the database.
Fire a Generic Event event that can be processed by the listeners.
----
Execution
Time (on server): Thu Sep 24 2020 11:49:42 GMT-0400 (Eastern Daylight Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2020-09-24 11:49:42,861 WARN [runner.ScriptBindingsManager]: Severity Value: Major
2020-09-24 11:49:42,863 WARN [runner.ScriptBindingsManager]: SetDueDate:2020-11-23 11:49:42.863
----
Due Date is in Screen/Field Scheme for issue
Create Issue, Due date not filled manually
The field 'Due Date' does not have value for issue after Create.
Community moderators have prevented the ability to post new answers.
Hi @Chris Cralle
You can move your script to the last position in your workflow and add this code :
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
//your code
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
issueManager.updateIssue(user,issue,EventDispatchOption.DO_NOT_DISPATCH,false)
I hope this help you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.