Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,366
Community Members
 
Community Events
168
Community Groups

how Add to my cf calendar +14 days ?

Edited

Hello, in my separate date field, the value should be displayed = present time + 14 days

But the code from the documentation does not work, please help!
use scriptrunner (post-function)


my code :

import com.atlassian.jira.component.ComponentAccessor

import java.sql.Timestamp

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// a date time field - add 14 days to current datetime

def dateCf = customFieldManager.getCustomFieldObjectByName("my_calendar_deadline")

issue.setCustomFieldValue(dateCf, new Timestamp((new Date() + 14).time))

erfq.png

уацуа.png

1 answer

1 accepted

2 votes
Answer accepted

Hi @Oliver Smith

It looks like you are missing a step in your code, which is why it is not updating as expected.

You will need to use the issue manager to trigger the update, i.e. something like:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption


def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
....
....
....
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

So for your code to work, you need to modify it to something like:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import java.sql.Timestamp

def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// a date time field - add 14 days to current datetime

def dateCf = customFieldManager.getCustomFieldObjectByName("my_calendar_deadline")

issue.setCustomFieldValue(dateCf, new Timestamp((new Date() + 14).time))

issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Please note that this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram

@Ram Kumar Aravindakshan _Adaptavist_ 

thank you very much, I really appreciate your help! It works ! Have a nice day 

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events