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))
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
@Ram Kumar Aravindakshan _Adaptavist_
thank you very much, I really appreciate your help! It works ! Have a nice day
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.