Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

203 views 6 7
Read article

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