Hello,
Our "Story" issue type has a custom field named "Scheduled Release". Whenever this field is updated, I'd like it to be synced into all of the issue's sub tasks (the issue also has custom sub tasks types) which in turn also have a custom field named "Scheduled Release". I figured I should have a custom listener with the "CustomFieldUpdatedEvent" event, but I can't figure out the exact inline script I need to add.
Any help will be much appreciated.
Thank you!
Nir
Hello @NBE,
I wrote a script for you. I'd appreciate it if you let me know the result after trying. Feel free to ask if you have question about the code. Hope this helps.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.field.CustomFieldUpdatedEvent
import com.atlassian.jira.issue.Issue
if(event.getCustomFieldId() == "Scheduled Release ID" && issue.getIssueTypeId() == "story issuetype id"){
def subtasks = issue.getSubTaskObjects()
def customfield = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("Scheduled Release ID")
def scheduledRelease = customfield.getValue(issue)
for (Issue subtask : subtasks){
customfield.updateValue(null, subtask , new ModifiedValue(subtask.getCustomFieldValue(customfield), scheduledRelease), new DefaultIssueChangeHolder());
}
}
Regards,
Orkun Gedik
Hi @Orkun Gedik
Thank you very much for taking the time to help me.
Pasting your code into the inline script I get a couple of errors, all of them in this line:
customfield.updateValue(null, subtask , new ModifiedValue(subtask.getCustomFieldValue(customfield), scheduledRelease), new DefaultIssueChangeHolder());
So I tried importing these classes:
Your help is much appreciated.
Nir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome @NBE, can you share your error logs please.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No error logs... it fails on the validation of the inline script.
See screenshot here: https://www.screencast.com/t/A4c4mNd9g
Thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the screenshot, imports are missing. Please import DefaultIssueChangeHolder and ModifiedValue then share screenshot again.
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.
Can you add the line below, just after the imports
Issue issue = event.issue
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.
Also, I tried running it without the if line, as shown below. In this case the script runs properly, but it does not execute what it should, i.e. - when I update a story's "Scheduled Release" field, it does not copy the value to all this story's sub tasks. Their "Scheduled Release" field remains empty.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.field.CustomFieldUpdatedEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
Issue issue = event.issue
//if(event.getCustomFieldId() == "Scheduled Release ID" && issue.getIssueTypeId() == "story issuetype id"){
def subtasks = issue.getSubTaskObjects()
def customfield = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("Scheduled Release")
def scheduledRelease = customfield.getValue(issue)
for (Issue subtask : subtasks){
customfield.updateValue(null, subtask , new ModifiedValue(subtask.getCustomFieldValue(customfield), scheduledRelease), new DefaultIssueChangeHolder());
}
//}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getCustomFieldObject() method needs customfield id like
getCustomFieldObject("customfield_1234")
Do not pass the paramater as a customfield name.
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 are welcome :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @NBE,
Please have a look on similar article and try substituting with your custom field.
Thanks,
Ram.
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.