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

Hi,

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

@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

image.png

You will end up here : 

image.png

Antoine

@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

@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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

365 views 1 3
Join discussion

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