Hello,
In need help in script runner. I have 3 date fields such as start date, duration and end date, the end date should auto populated in view screen based on start date + Duration provide in create screen. Please help me with right code to get this output with help of script runner under behaviours.
Thanks,
Linijesh
Hi @Linisha Jesh Instead of behaviour it is better to use scripted “End Date” field. so that once you create the issue, system calculate sum and Put in end date Scripted field. Try below code replace between by addTo
Replace Lower Date field and higher date field with Start date and duration respectively.
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import java.time.temporal.ChronoUnit
// Get the required component
def customFieldManager = ComponentAccessor.customFieldManager
// The name of the lower date custom field
final String lowerDateCustomFieldName = "Lower Date Custom Field"
// The name of the higher date custom field
final String higherDateCustomFieldName = "Higher Date Custom Field"
// Get the custom field objects
def lowerDateCustomField = customFieldManager.getCustomFieldObjects(issue).find { it.name == lowerDateCustomFieldName }
def higherDateCustomField = customFieldManager.getCustomFieldObjects(issue).find { it.name == higherDateCustomFieldName }
if (!lowerDateCustomField || !higherDateCustomField) {
log.info "Could not find one ore more of the provided custom fields"
return null
}
// Get the date values from both issues
def lowerDateValue = issue.getCustomFieldValue(lowerDateCustomField) as Timestamp
def higherDateValue = issue.getCustomFieldValue(higherDateCustomField) as Timestamp
// Transform both values to instants
def lowerDateInstant = lowerDateValue?.toInstant()
def higherDateInstant = higherDateValue?.toInstant()
// Change the chrono unit to obtain the difference in other time unit.
final chronoUnit = ChronoUnit.DAYS
// Calculate the difference between the lower and the higher date.
lowerDateInstant && higherDateInstant ? chronoUnit.between(lowerDateInstant, higherDateInstant) : null
Source of code : https://library.adaptavist.com/entity/calculate-the-difference-between-two-dates
I have already writen script for start date in the transistion to add 20 min to the current time. now i have to fetch this start time + duration to end time with help of behaviour. Can you please help with this..
Thank you,
Regards,
Linijesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Linisha Jesh you want to update end date field value after a transition? As per the tags it seems that you are using Jira Cloud. In jira cloud behaviour is not available. In cloud You can do It via post function or via listener or use scripted end date field.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.