How to create a post function ScriptRunner script for advancing a custom Date Picker field by X days.

We have a workflow that has a transition for auto-advancing a custom Date Picker field by 21 days and need some guidance in creating the Post Function ScriptRunner script for advancing the date.

Many thanks for your willingness to assist.

2 answers

This widget could not be displayed.

The example here explains how to update multiple custom field types: https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/set-issue-attributes.html

Line 28/29 shows how to advance a date field by 7 days...

So removing what you don't need, you should end up with something like:

import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// a date time field - add 7 days to current datetime
def dateCf = customFieldManager.getCustomFieldObjectByName("First Date") // Date time fields require a Timestamp
issue.setCustomFieldValue(dateCf, new Timestamp((new Date() + 7).time))

Sir Jamie,

Good to hear from you.

Many thanks for your concrete tips!

This widget could not be displayed.

Hello, @Jamie Echlin [Adaptavist]

Can you please explain instead of Timestamp, what would be needed if the date picker is only a date picker and not a date time picker?

Thank you in advance for your help. 

It's the same thing, it will just ignore/truncate the time portion.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

507 views 3 18
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you