Forums

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

Custom Field set to current date - Script runner

Chandan Gupta
Contributor
August 7, 2018

I have created a custom field with name 'Begin Date' which is type of Date Picker. In my work flow I want to put the post function that as soon as I make a transition of issue from Created to In-progress, Begin Date should populate with Current Date.

I tried with custom script in Script Runner but failed. Help please?

2 answers

2 accepted

1 vote
Answer accepted
Alexey Matveev
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.
August 7, 2018
Chandan Gupta
Contributor
August 7, 2018

Thanks Alexey.

 

But I got 

Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB java.sql.Timestamp cannot be cast to java.lang.String

It seems that you have tried to perform an illegal workflow operation.. any idea??

Alexey Matveev
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.
August 7, 2018

What is the type of your custom field? 

Chandan Gupta
Contributor
August 7, 2018

One custom field is Date Picker and another is Text Field

Alexey Matveev
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.
August 7, 2018

According to the error you are trying to save the date into your Text Field

Like Etienne Farnault likes this
Chandan Gupta
Contributor
August 7, 2018

Hmm, you are right. When I tried with date picket it worked. Is there any way we can convert it to String and add it to text field as well.

Thanks for all the help here..  

Chandan Gupta
Contributor
August 7, 2018

Final script I used is 

 

import com.atlassian.jira.component.ComponentAccessor

import static java.lang.Math.*

import java.sql.Timestamp

def Begin_Date = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Begin Date")

// get today's date

issue.setCustomFieldValue(Begin_Date, new Timestamp((new Date() + 1).time))

Like Siesta likes this
Alexey Matveev
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.
August 7, 2018

You can convert the date to a string like this:

new Timestamp((new Date() + 1).time.toString()

Mike_Low May 15, 2020

Thanks the script Chandan provided immediately above worked for me. Just removed the +1 to be the current date.

0 votes
Answer accepted
Francesc_Arbó
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.
August 7, 2018

Hi @Chandan Gupta,

 

You can edit the date custom field configuration an check the Current Date option.

date config.PNG

In addition, you can use the Suite Utilities for Jira app in the postfunction and add the Update Issue Custom Field in order to add the current date in that specific transition.

Suggest an answer

Log in or Sign up to answer