how Add to my cf calendar +14 days ?

Alex
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2022

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

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 19, 2022

Hi @Alex

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

Alex
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2022

@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
AUG Leaders

Atlassian Community Events