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)
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:-
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:-
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:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
FYI, the example you have shared is for the Behaviour and not appliable for Post-Function.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.