I have the below scenario,
Field 1) B Due Date (Date picker)
Field 2) Due Date (At the Epic issue Type)
I want to make sure that Field 1 copies the value of Field 2 the FIRST time its filled (When ever a user fills in the Due Date). Later , even thought the Field 2 value might be changed, the field 1 must not change its value and must be non editable (only viewable)
Apart from this, if an Epic does back to certain statuses, I want the B Due Date to should clear and the script start fresh
Is it possible incorporate this ?
Hi @Aisha M ,
You can use a listener to copy the date on Issue Created and Issue Updated events, and any other event triggered when you add a value for Field 2. Check if this field is on a screen used in the workflow ; if yes, check the event triggered on this transition.
The code would look like :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def issueType = issue.getIssueType().getName()
if (issueType == "Epic"){
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def dueDateValue = issue.getDueDate()
int date1id = 12501
def date1 = customFieldManager.getCustomFieldObject(date1id)
def date1Value = issue.getCustomFieldValue(date1)
if (!date1Value && dueDateValue){
date1.updateValue(null, issue, new ModifiedValue(date1Value, dueDateValue), new DefaultIssueChangeHolder())
}
}
If you want to clear the field going back on a status, use this code post-function :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def date1 = customFieldManager.getCustomFieldObject(date1id)
def date1Value = issue.getCustomFieldValue(date1)
date1.updateValue(null, issue, new ModifiedValue(date1Value, null), new DefaultIssueChangeHolder())
The first script will then re-execute if the field 2 is filled.
If you are using a global transition on the Target status, you could add this groovy condition :
passesCondition = (issue.getStatus().getName() != "Source")
And add a specific transition from status Source to Target using the script above.
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.