Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,364,916
Community Members
 
Community Events
168
Community Groups

Compare fields of linked issues

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! 

1 answer

Hi Yurii,
I would say the solution would depend heavily on how you want this to occur.
The different ways this could be triggered

  • Manual (you run the script)
  • Scheduled
  • When the issue is updated

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

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

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. 

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);
}
}
}



Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events