It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Need help with Script Listeners to copy and lock a field value


Can anyone please help me with how to use Script Listeners for the below scenario,

Field 1) Epic Due Date

Field 2) Baseline Due Date (Date picker)

I want to make sure that Field 1 copies the value of Field 2 the FIRST time its filled while the issue is created. 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).


Thank you !

2 answers

1 accepted

1 vote
Answer accepted
Antoine Berry Community Leader Oct 15, 2019

Hi @Aisha M ,

I would advise to create a Script Listener on the Create Issue event in appropriate projects. Make sure that this event is triggered in the workflows.image.pngUse this script (update the ids) : 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def customFieldManager = ComponentAccessor.getCustomFieldManager()

int date1id = 12500
int date2id = 12501

def date1 = customFieldManager.getCustomFieldObject(date1id)
def date2 = customFieldManager.getCustomFieldObject(date2id)

def date1Value = issue.getCustomFieldValue(date1)
def date2Value = issue.getCustomFieldValue(date2)

date1.updateValue(null, issue, new ModifiedValue(date1Value, date2Value), new DefaultIssueChangeHolder())

Make sure field 1 is only on the View Issue screen so users cannot edit it.


@Antoine Berry  Thanks a million Antoine. Will test this out and let you know.

@Antoine Berry Hi Antoine, I couldn't find a script listener option either at validators/post functions of the Create Issue transition . . Do i have to add he listener from the Add-on page or something ?

Thank you

Antoine Berry Community Leader Oct 18, 2019

Hi, just type GG > script listeners


You will end up here : 



@Antoine Berry  That worked !!!! Thank you sooooooo much !!! :) 

Antoine Berry Community Leader Oct 22, 2019

You're welcome, always glad to help !

@Antoine Berry  Hi Antoine. Just a quick help, how do I make sure, this is available for the issues which was existing before the listener was created ? 

I tried adding "Issue updated' in the events, but it gives an error. But the script works wonderful for newly created issues. 

Antoine Berry Community Leader Oct 23, 2019

Hi @Aisha M , I do not see any reason why this should not work on Issue Updated event. This event triggers when you edit the issue. You might want to create custom events for your needs.

Also you should investigate the logs to check why it is failing.


@Antoine Berry  Thank for the help :) But unfortunately for me, they have changed the requirement to a completely different one and it sounds much more complicated :(

Now its like the uneditable field must capture the dates on when the BASELINE DUE DATE was entered and later whenever it gets modified . Planning to post about it and get help from the members

Antoine Berry Community Leader Oct 25, 2019

Would you mind opening a new ticket then ? It would be easier to track which post answers which question.

Hi @Antoine Berry , LOL, this is the exact same requirement I have again. Only difference is,

Field 1) Baseline 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).

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you