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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

4,557 views 12 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you