Simple scriptrunner set DueDate help

Chris Cralle September 24, 2020

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.

 

1 answer

1 accepted

0 votes
Answer accepted
Gustavo Félix
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2020

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.

Chris Cralle September 28, 2020

That did the trick. Thank you very much.

Like Gustavo Félix likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.8.1
TAGS
AUG Leaders

Atlassian Community Events