Hi,
I wrote a script for behavior to get ticket's due date and the current date of the system.
If due date passed then a custom field should be required on transition screen when going from any status to close.
Here's my script:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import java.text.SimpleDateFormat
com.atlassian.jira.issue.issuetype.IssueType
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormatter
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
FormField dueField = getFieldByName("duedate")
FormField cfValue = getFieldByName("DTD - Root Cause Category")
String timeStamp = new SimpleDateFormat("dd/MMM/YYYY").format(new Date());
String dateGA=dueField.getValue()
Date newDate1=Date.parse("dd/MMM/YYYY",dateGA)
Date newDate3=Date.parse("dd/MMM/YYYY",timeStamp)
if(newDate3.before(newDate1))
{
cfValue.setRequired(true)}
There're no error, but the results are not as expected.
Any ideas?
Thanks!
You should change your script to
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import java.text.SimpleDateFormat
com.atlassian.jira.issue.issuetype.IssueType
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormatter
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
FormField dueField = getFieldById("duedate")
FormField cfValue = getFieldByName("DTD - Root Cause Category")
String timeStamp = new SimpleDateFormat("dd/MMM/YYYY").format(new Date());
String dateGA=dueField.getValue()
Date newDate1=Date.parse("dd/MMM/YYYY",dateGA)
Date newDate3=Date.parse("dd/MMM/YYYY",timeStamp)
if(newDate3.before(newDate1))
{
cfValue.setRequired(true)}
The changed line is FormField dueField = getFieldById("duedate"). All system fields you should reference by getFieldById
And your script should be attached to the DueDate serverside script (You need to add DueDate field in your behaviour and attach the script to the field)
Hi Alexey,
Thank you for your answer.
I follow your suggestions and when duedate had passed (compare to current date) the behavior is not working as expected. The custom field is not required on transition.
Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Log values for your fields and see what s wrong.
add log.error(newDate1) and log.error(newDate2). Then have a look what is logged in the atlassian-jira.log
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found the following line in jira.log:
fieldId: duedate, file: <inline script> java.lang.IllegalArgumentException: Cannot format given Object as a Date
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the problem is with
Date newDate1=Date.parse("dd/MMM/YYYY",dateGA)
try to put log.error(dateGA) before the mentioned above line and see what is in the log.
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.