Need listener to copy and lock the first value from a different field ?

Aisha M August 17, 2020

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 ?

1 answer

1 accepted

2 votes
Answer accepted
Antoine Berry
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 17, 2020

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. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events