Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Use ScriptRunner Behavior to add 1 day to "Due Date" upon submittal of issue

Durell Demartini
Contributor
July 26, 2023

Hello,

Upon submittal of a form in one of our service portals, we'd like to have 24 hours (or 1 day, however it needs to be interpreted) added to the system field, "Due Date." I've created this as a Behavior in ScriptRunner, but it's not working. 

 

import java.sql.Timestamp

import java.util.concurrent.TimeUnit

def start = getFieldById("duedate")

def date = issueContext.created

def defaultValue = new Date(date.getTime() + TimeUnit.DAYS.toMillis(2)).format("dd/MMM/yy")

if (! start.getValue()) {

 start.setFormValue(defaultValue)

}

Thanks in advance for any suggestions you can offer! 

 

1 answer

1 accepted

0 votes
Answer accepted
Tim Perrault
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.
July 26, 2023

Hi @Durell Demartini 

 

I haven't tested your script, but I would try moving this script to a custom script post function on the create step of your workflow.

Make sure the post function is before the Creates the issue originally step

Screenshot 2023-07-26 180040.png

Tim Perrault
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.
July 26, 2023

You could probably simplify the code if it was a postfunction since it would grab the date at time of creation.

I've tested this in my environment and it is adding a day to the selected due date.

 

import java.sql.Timestamp

def cfDate = issue.dueDate;

def newDueDate = new Timestamp(cfDate.getTime() + 1 * 24 * 60 * 60 * 1000)

issue.setDueDate(newDueDate)

 

Durell Demartini
Contributor
July 27, 2023

Thanks so much, @Tim Perrault

Your suggestion worked. I greatly appreciate your assistance!

Like Tim Perrault likes this

Suggest an answer

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

Atlassian Community Events