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.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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") }
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
For the issue status, it has lot of different types, the first step is Open-> Site Manager
workflow schemes:
so i go to that flow and press "Post Functions"
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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") }
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great,
we need to first put the value in variable. and then
the logic should be after: if(linkType == "Customer Issue")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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))
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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") }
}
}
}
what`s wrong here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
now it tells me to use getCustomFieldObjectsByName("עדכון אחרון")
I tried to use getCustomFieldObject(long) and to write the FieldID(13600) but it didnt work...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can ignore this warning, or else you can switch to another method
def cfUpdate = ComponentAccessor.customFieldManager.getCustomFieldObjectById("customfield_13600")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Leo the script was failed.
Its alerts that there is no such function:getCustomFieldObjectById()
this is how my issue look:
and the link "Customer Portal issues":
the Code is as you send me:
any suggestion?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.