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

automatically changing link status according to new change in issue status

Hi all,

I defined in my Jira:

when I create a new issue then also link with the same status will be created.

issue status(open) -> link status(open)

 

now I want to add a condition that when issue status is a change for example to 'A'

then its Link status will change to 'B'. 

tried to look up for examples of post-function but couldn't find anything.

1 answer

1 accepted

2 votes
Answer accepted
Leo Community Leader Jan 28, 2020

Hi @peter_zubkov,

If I understood correctly you want to change the status of linked issue when current issue move/changes to new status

If so, you may need to go with post-function not a condition

There are couple of ways I use to go with 

1.  Using "Linked Transition (JSU)" post-function from JSU plugin

2. or using Scriptrunner's post-function by writing custom groovy script

If you search in marketplace you may find similar apps too

 

BR,

Leo

I need to check if the current issue has issue-link of type "Customer Portal issue"

then

  if: the issue status is "2"  

    then change issue link of type "Customer Portal issue"  status to "5"

 

will you be able to assist?

Leo Community Leader Jan 28, 2020

Place this script in 2nd status's post-function

I haven't tested this code, it may require some minor changes though

Check exact type name (I used outward type here, you can change it to inward if you want

import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl

def LINK_NAME = "Customer Portal issue"
def customerIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())?.findAll {it.issueLinkType.outward == LINK_NAME}
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 5
def transitionValidationResult
def transitionResult

if(customerIssues){
customerIssues.each { i ->
if(i.destinationObject.getStatus().name != "Required One"){
transitionValidationResult = issueService.validateTransition(currentUser, i.destinationObject.id, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }
else
{ log.debug("Transition result is not valid") }
}
}
}
}

tnx for your quick answer!

1. at "action id"  if i want "under support" should i put 2 or 11? i tried both and it didnt changed.

2. customerIssues.each run on all issues link? 

image.png

Leo Community Leader Jan 28, 2020

1. you should use Transition id(3rd column), for Under Support --> 11

2. Yes, if there are more customer issues linked to it. it'll run for all of them which all linked to current issue

it will have only one link of type "Customer Portal issues" in each issue.

i need to ask if issue status if changed from "open" to "SiteMeneger" then chage link issue status to "underSupport" (11)

 

so what is that line means: 

i.destinationObject.getStatus().name != "Required One"

Leo Community Leader Jan 28, 2020

Then this would be

i.destinationObject.getStatus().name != "Under Support"

just checking if linked issue is already in Under support status or not, if not script will make the transition else will leave it as it is

Note: you should use customerissues.each though it'll have only one issue will be stores as a list type and that needs to go through iteration process 

Hi Leo, 

I made a rule: when i create an issue of type: IMPSUP 

then the link of type "Customer Portal issues" who is connected to the issue, will be created.

image.pngimage.png

For the issue status, it has lot of different types, the first step is Open-> Site Manager 

workflow schemes:

image.png

 so i go to that flow and press "Post Functions"

image.png

 

I want to check if only the issue has:

the link type of Customer Portal issues and the issue (IMPSUP) change from Open to SIte Manager -> then link issue Customer Portal issues status will be changed from Open To Under Support.

 

 

Your code check if the link issue status changed... how do I make it check if the issue status changed?

Leo Community Leader Jan 28, 2020

When you add this script in the mentioned transition(open --> Site Manager), you need not to check current issue status. as this will run only on site manager's status change

Ok,

Its works perfectly!

but only when i remove the LINK_NAME search.

 def customerIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());

and then the logic work on all links of the issue.

this is not working:

def LINK_NAME = "Customer Portal issues";
def customerIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())?.findAll {it.issueLinkType.outward == LINK_NAME};

 

any suggestions?

Leo Community Leader Jan 29, 2020

I just tweaked code using another method, this should solve your issue

There are couple of things to notice here, 

1. I'm fetching outward linked issues(check issue links whether they are outward or inward)

2. In linktype checking I'm checking linktype name neither inward name nor outward name

you'll have to check that particular link type's name, inward and outward to modify below script

import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 5
def transitionValidationResult
def transitionResult

List allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
def linkType = issueLink.issueLinkType.name
if(linkType == "Customer Issue"){
def linkedIssue = issueLink.getDestinationObject().id
transitionValidationResult = issueService.validateTransition(currentUser, linkedIssue, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }
else
{ log.debug("Transition result is not valid") }
}
}
}

 

BR,

Leo

great, its works!

thank you for your help.

Hi Leo,

 

I`m trying to make a customFiledId(13600) named: lastUpdate, to be copied from issue to link("Customer Issue") at each Transition.

can't figure how to copy the value of the filed inside For loop

Leo Community Leader Feb 05, 2020

Hi @peter_zubkov,

I'm not sure I got you or not, If I understood correctly you want to retrieve all issues using linked issue type and iterate over them

below script I used to iterate over all linked issues and make a transition, you just need to tweak this script for your requirement

List allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
def linkType = issueLink.issueLinkType.name
if(linkType == "Customer Issue"){
def linkedIssue = issueLink.getDestinationObject().id
transitionValidationResult = issueService.validateTransition(currentUser, linkedIssue, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }
else
{ log.debug("Transition result is not valid") }
}
}
}

Ok,

I just need to get on each Transition -  issue.customFiled.id(13600) and set it to:

issue.link("Customer Portal issues").customFiled.id(13600)

can you rewrite the logic?

Leo Community Leader Feb 05, 2020

Ok got you, you want to copy particular field value to linked issue's field(same). it's not big deal though, I can rewrite but can't verify now. so may require some minor changes

Great,

we need to first put the value in variable. and then

the logic should be after: if(linkType == "Customer Issue")

Leo Community Leader Feb 05, 2020

Check the type(s) are inward or outward

import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;

def cfUpdate = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Custom Field Name")

List allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
def linkType = issueLink.issueLinkType.name
if(linkType == "Customer Issue"){
def linkedIssue = ComponentAccessor.getIssueManager().getIssueObject(issueLink.getDestinationObject().key)
linkedIssue.setCustomFieldValue(cfUpdate, issue.getCustomFieldValue(cfUpdate))
}
}

import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.issue.IssueInputParametersImpl;

def cfUpdate = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("עדכון אחרון")
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
IssueService issueService = ComponentAccessor.getIssueService();
def actionId = 11;
def transitionValidationResult;
def transitionResult;
List allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());

for (Iterator outIterator = allOutIssueLink.iterator(); outIterator.hasNext();)
{
IssueLink issueLink = (IssueLink) outIterator.next();
def linkType = issueLink.issueLinkType.name
if(linkType == "Customer Portal issues")
{
def linkedIssue2 = ComponentAccessor.getIssueManager().getIssueObject(issueLink.getDestinationObject().key)
linkedIssue2.setCustomFieldValue(cfUpdate, issue.getCustomFieldValue(cfUpdate))
def linkedIssue = issueLink.getDestinationObject().id
transitionValidationResult = issueService.validateTransition(currentUser, linkedIssue, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid())
{
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }
else
{ log.debug("Transition result is not valid") }
}
}
}

image.png

 

what`s wrong here?

Leo Community Leader Feb 05, 2020

Here is the spot

def cfUpdate = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("עדכון אחרון")

it's not getCustomFieldObjectsByName() "s" should be removed if not it'll throw list of custom fields but the method is for a field 

it should be written as

def cfUpdate = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Custom Field Name")

@Leo 

now it tells me to use getCustomFieldObjectsByName("עדכון אחרון")

image.png

 

I tried to use getCustomFieldObject(long) and to write the FieldID(13600) but it didnt work...

 

Leo Community Leader Feb 05, 2020

@peter_zubkov 

you can ignore this warning, or else you can switch to another method

def cfUpdate = ComponentAccessor.customFieldManager.getCustomFieldObjectById("customfield_13600")

@Leo the script was failed.

Its alerts that there is no such function:getCustomFieldObjectById()

 

this is how my issue look:

image.png

and the link "Customer Portal issues":

image.png

the Code is as you send me:

image.png

 

any suggestion?

Suggest an answer

Log in or Sign up to answer
TAGS

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