How to set 1/1/2999 date to Target Date custom date field

Omprakash Thamsetty
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.
February 8, 2024

How to set the date 1/1/2999 to 'Target date' custom date field in post-function. I know there is a function available but I want to write a groovy script to check summary. 

 

If the summary = AAAA

then 

set target date = 1/1/2999

else

set target date = today +7 days. 

 

I am able to manage setting the 'ELSE' part but trying to figure out to set the static value. 

Here is the sample code that I am trying

Error in my code 

issue.setCustomFieldvalue(TD,input)

Can not matching method. I may have to convert string to date or missing something. 

Any help much appreciated.


if(issue.summary !='AAA'){

if (TDV == "" || TDV == null) {

    Calendar cal = Calendar.getInstance();

  // set due date to: current date + 8 days

  Timestamp DefTDD = new Timestamp(cal.getTimeInMillis()+ 14*1000*24*60*60);

  //DefTDD.toString()

    issue.setCustomFieldValue(TD, DefTDD)

   // issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH ,false)

}

}else{

def pattern = "dd-MM-yyyy"

def input = "01/01/2999"

def date1 = Date.parse(pattern, input)

    issue.setCustomFieldvalue(TD,input)

}
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH ,false)

2 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 19, 2024

Hi @Omprakash Thamsetty

For your requirement, I suggest you look into ScriptRunner's HAPI feature.

Below is a sample working code for your reference:-

if (issue.summary == 'AAAA') {
issue.set {
setCustomFieldValue('Date 1', '01/Jan/2999')
}
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Post-Function configuration:-

post_function_config.png

I am also including a couple of test screenshots for your reference:-

1. When the issue is first created no value is added to the date field, i.e. Date 1 as shown in the screenshot below:-

test1.png

2. Once the issue transitions to In Progress, the Date 1 field is updated to the value 1/Jan/99, i.e. 1st January 2099 as shown in the screenshot below:-

test2.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

 

0 votes
Uday Kiran Bhaviri
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.
February 8, 2024

Hi @Omprakash Thamsetty 

You can try the code below from Adaptavist

https://library.adaptavist.com/entity/set-date-field-value

Mark it answered if it is helpful to you.

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 19, 2024

Hi @Uday Kiran Bhaviri

FYI, the example you have shared is for the Behaviour and not appliable for Post-Function.

Thank you  and Kind regards,

Ram

 

 

Suggest an answer

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

Atlassian Community Events