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 !
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.Use 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, just type GG > script listeners :
You will end up here :
Antoine
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.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Would you mind opening a new ticket then ? It would be easier to track which post answers which question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Yes, I have :) If you are interested to have a look at the new question , please use the link below
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
The logic behind is exactly the same. Create a listener and link it to each event where users might update the due date (field 2). Is the field is mandatory on creation, only use the createIssue event.
Use this script :
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())
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , I will test this out :) Thank you a million times for always taking the effort to help ;(
But, what if an user doesn't add a Due Date while creating an Epic, and do it at a later point of time ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That is why you need to link this script to any event that might be triggered when the user changes/adds a value.
You need to check the workflow transitions post functions. By default on creation the event "issue created" is triggered. Then in others transitions it is most likely a "Generic event", or "Issue Resolved" on resolution, and so on. You can replace them by existing or custom events if needed.
So, on issue creation, it will most likely trigger "issue created", on edition "Issue updated", and "generic event" if the user adds a value using a transition screen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Okay got it. Aldo, this listener should be created at the workflow or throught the Add On page ?
We now have a separate workflow for the EPIC issue type. I have defined the status flow below,
Create > BackLog >Pre Planning > Ready for Planning > Planning > Ready & Planned > Working >Validated>Delivered , also a Cancelled status
So, all these status are global transitions. (So, an Epic can be moved to any status at any point)
They also have another point here, that if an Epic does back to the status Ready for Planning from Working, they want the Baseline Due Date it should clear and start fresh
Is it possible incorporate this ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For the listener, just type G+G > Script listeners. Youh should only check transitions with an associated screen which contains the due date (otherwise the user cannot change it). Then, check which event is fired :
Once you have collected all the events which might cause an update of the due date field, create the script listener and link it to these events.
Finally, add a scriptrunner post function to clear the due date on the Ready for planning transition. This script should work :
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())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry , Okay, I think I got the steps.
1) Create a script listener with the script for every event a user might update Due Date - Issue created, Issue updated etc
2) Then go to that particular workflow step and add the above post function to clear Baseline Due Date.
(But I want this to happen only if an Epic is moving back from Working to Ready for Planning)
Will test this out first and see if I'm able to make it work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is correct !
You could add this snippet to check if due date has been changed :
def dueDateChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "duedate"}
if (dueDateChanged) { ...
at the top of the script but unfortunately this does not work at creation, so you would need two listeners.
You could achieve the due date clear on only one transition by having two transitions and hiding one or the other using a condition in the post function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Hi, I am able to complete the first part of the requirement. I created the listener for "Issue Created" & "Issue Updated" events, and the script is working great. Its copying and locking the first value of the Epic Due Date. *happy dance* Thank you million million times !
Now, I need to figure how to implement the second part that is clear the script when the issue moves back to an older status, , lol, thats what's confusing me so much :) I ll test that let you know :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
So I think you got most of the requirement right. You could make the last part working with this method. Have two transitions going the "Ready for planning" status :
passesCondition = (issue.getStatus().getName() != "Working")
Let me know if that helped.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , I don't understand the second part. You have given the below three codes, which one should I use, I m so confused :(
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())
def dueDateChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "duedate"}
if (dueDateChanged) { ...
passesCondition = (issue.getStatus().getName() != "Working")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M , I understand that can be confusing. You are already using this script successfully if I understood correctly :
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())
}
}
It copies the due date value into the baseline due date if the baseline due date is empty.
This part is just a snippet you can add to check if the due date has been changed :
def dueDateChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "duedate"}
if (dueDateChanged) { ...
but it does not work for the Issue Created event, so you might ignore it.
This snippet is used in the global transition to the "Ready for planning" status as a custom groovy condition.
passesCondition = (issue.getStatus().getName() != "Working")
it ensures that when the issue is on the "Working" status, the user only sees the additional transition from "Working" to "Ready for planning" (I switched the two statuses in the previous comment by mistake). In this specific transition use this script :
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())
It will clear the baseline due date.
I guess this should fulfill the requirement. Let me know if that is not clear.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , Thank you for patiently explaining me the steps :)
So, I need to create a new transition from "Working" to "Ready for planning", and then add the above final script right ? If yes, should this be a post function script runner script ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes !
So in total you would need one listener, one groovy condition and one groovy post function. :)
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.
Hi @Antoine Berry , I was able to set up the second part of the requirement using Project Automation too. I'm scared it looks way too simple :D
Anyway, I ll try out the script condition mentioned above as well. I ll see what the users prefer. But thank you sooo much for taking the time :):):)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Hellooo, can you please post the above answer to the below link , so the answer can be accepted :)
Thank you soo sooo much for your constant help ^_^
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
You might want to create a new question with the full requirement otherwise it would be a bit odd. Meaning the part where you need to clear the value when transitionning to "Ready for planning". Also I feel a bit uncomfortable answering after the all mighty Nick lol :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry I will modify the question to the exact outcome. I just don't want to miss marking your answer ! :) Sorry about that
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Do you want to create a separate question without Nick's comment ?? I personally feel you are more smarter and infact much more helpful than anyone on this community !!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah you could also edit your question to include the whole requirement. It is just that I felt a bit rude to add an answer that would fit more than the original question would ask for when Nick has given a valid answer already. :)
(Also I cannot rival with Nick, he provided more than 60000 answers ! He's our guru :D)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Lol, okay :) I ll create a new detailed question for it & share you the link. I just updated the details for the previous question.
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.
@Antoine Berry Hello !! I m sooo sorry for being gone :D I had to take off due to personal reasons :) so so sorry. Anyway back to work :(
I have created a new post for the above solution :) Can you please post the answer to the below link ? I ll modify the question more if required :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
Do not be sorry, I hope you are doing ok and everything is fine on your side now.
Good luck with work :) I have answered your question, thanks for having taken the time to create one.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Absolutely nott ! Thanks to YOU for taking the time & effort to answer my frequently changing questions :):) I m sure no one would have helped as much !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M try this link, it might help you with your request: https://community.atlassian.com/t5/Jira-Core-questions/copy-date-between-2-custom-fields/qaq-p/396363
Thanks,
Mihai S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.