Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,559,866
Community Members
 
Community Events
185
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
AUG Leaders

Atlassian Community Events