Need assistance with Scriptrunner.
I am trying to find a script to do the following:
Due date is set at create.
When issue is created I need a post function or listener to copy the date value to another date field that will not be editable.
We are doing this to keep track of the original due date.
This is for Scriptrunner for Data Center
Hi @Hector Hood
For your requirement, you will need to use both the Post-Function as well as the Behaviour.
The Post-Function can be used to pass the value from the Due Date field to the custom field. However, the Post-Function is unable to set a field to Read-Only. To do this, you will need to use Behaviour.
Below is a sample working code for the Post-Function:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def mutableIssue = issue as MutableIssue
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def originalDueDate = customFieldManager.getCustomFieldObjectsByName('Original Due Date').first()
mutableIssue.setCustomFieldValue(originalDueDate, issue.dueDate)
issueManager.updateIssue(loggedInUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
Please note, this sample code is not 100% exact to your environment. Hence, you will need to modify it accordingly.
You will need to use the Custom Script Post-Function.
Below is a print screen of the Post-Screen configuration:-
Next, you will need to setup a Behaviour Initialiser configuration for the custom field, which contains a copy of the original date.
Below is the sample code that is used in the Behaviour:-
def originalDueDate = getFieldByName('Original Due Date')
originalDueDate.setReadOnly(true)
This ensures that if any modification is attempted to the custom field, the Edit dialog will be displayed, and the custom field will be in Read-Only mode.
Below is a print screen of the Behaviour configuration:-
I hope this helps to solve your question. :)
Thank you and Kind Regards,
Ram
Going to try this out. Thank I will report back shortly :)
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.