Hi Experts
Need help.....!
Using behavior script- trying to achieve below
Need to Get value of Custom date field and then need set new value(10 days from the date selected in custom field) in Due Date field.
For example
Custom field Datefield selected as 26/Feb/2021
The in DUE DATE, need to set (10+(datefield Value)). So due date would be 7/Mar/2021
Can please help with logic and script.
Hi there,
You may use the script below;
Please do not forget to change the cf ID and username for the operation before use it.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.user.ApplicationUser
import java.text.SimpleDateFormat
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def issueManager = ComponentAccessor.getIssueManager()
def issue = underlyingIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
MutableIssue mTarget = (MutableIssue) issue
JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext()
authContext.setLoggedInUser(ComponentAccessor.getUserManager().getUserByName("admin")) //type username for change operation
ApplicationUser automationUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def dateFieldCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11998") //type cf id of the date field
def dateFieldValue = issue.getCustomFieldValue(dateFieldCF).toString()
def newDate = new SimpleDateFormat("dd.MM.yyyy").format(dateFieldValue).plus(10)
mTarget.setCustomFieldValue(dateFieldCF, newDate)
issueManager.updateIssue(automationUser, mTarget, EventDispatchOption.DO_NOT_DISPATCH, false)
Best Regards,
Burak
Hi @Burak Kaya
don't see in above code trying to set date for DUE Date -> System Field
Below is for example
Custom field ABC (Type - Date Field) selected as 26/Feb/2021
The in DUE DATE, need to set (10+(datefield Value)). So due date would be 7/Mar/2021
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.