Hi everyone,
I just started working with scripts and would appreciate your help!
Thee are linked Story and Bug, where Bug "blocks" Story
There is one custom field (customefield_1) - same in Bug and Story.
I want to compare this field in Bug with field in Story and, if value of Bug's field is higher - update field in Story with this value.
Could you please help me there?
Thanks!
Hi Yurii,
I would say the solution would depend heavily on how you want this to occur.
The different ways this could be triggered
If you could specify in better detail how you want this to run it would probably be easier to assist you.
Due to the performance impact of some "solutions" to this issue I have not listed them.
I would see this as running when an issue is updated.
If you can post what your script looks like at the moment we can see what you're missing.
Regards
Hi Jeff,
Thanks for the reply!
This should be triggered when I update the bug - actually moving it from one status to another, so I can use script in PostFunction.
Unfortunately, I don't have script now - as I'm trying to figure out of how to build it. Honestly, I'm reading the info now, looking on examples etc.
Thanks,
Yurii
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's a script I wrote.
It's completely un-tested so you might have to tinker a bit.
If you run into issue you cant fix, feel free to ask for help.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.issue.index.IssueIndexingService
/************************************/
def sourceFieldId = 12345;
/***********************************/
def sourceField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(sourceFieldId)
def parent = issue.getParentObject();
if(sourceField.getValue(issue) > sourceField.getValue(parent)){
MutableIssue mi = (MutableIssue) parent;
mi.setCustomFieldValue(targetField, );
ComponentAccessor.getIssueManager().updateIssue(currentUser, mi, EventDispatchOption.DO_NOT_DISPATCH, false);
boolean wasIndexing = ImportUtils.isIndexIssues()
IssueIndexingService issueIndexService = ComponentAccessor.getComponent(IssueIndexingService.class)
issueIndexService.reIndex(parent)
if(!wasIndexing)
ImportUtils.setIndexIssues(true);
}
Regards,
J
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much, Jeff!
However, if I didn't miss something, this script seems to work for Parent-Subtask connection, while I have 2 standard issues linked by "Blocked by / Blocks" link.
In my case, Bug "blocks" Story.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah sorry,
You're right about that.
Completely missed that, sorry about the delay in getting back to you.
I changed it a bit.
Try this, once again. havent tested it, if you run into any trouble just respond and I'll help fix it.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.issue.index.IssueIndexingService
//if swapping getInwardLinks() for getOutwardLinks() remember to replace Source with Destination inside the for loop
/************************************/
def sourceFieldId = 12345;
def linktypeId = 123456;
/***********************************/
def sourceField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(sourceFieldId)
def links = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for(link in links){
if(link.issueLinkType.id == linktypeId){
def otherIssue = link.getSourceObject();
if(sourceField.getValue(issue) > sourceField.getValue(otherIssue)){
MutableIssue mi = (MutableIssue) otherIssue;
mi.setCustomFieldValue(targetField, );
ComponentAccessor.getIssueManager().updateIssue(currentUser, mi, EventDispatchOption.DO_NOT_DISPATCH, false);
boolean wasIndexing = ImportUtils.isIndexIssues()
IssueIndexingService issueIndexService = ComponentAccessor.getComponent(IssueIndexingService.class)
issueIndexService.reIndex(otherIssue)
if(!wasIndexing)
ImportUtils.setIndexIssues(true);
}
}
}
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.