Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get/set Date field value using behavior in jira

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.


1 answer

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.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,

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you