Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Edit linked issue if main issue is edited

zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2018

Hello, guys!
I have two issues - "issue A" and "issue B".  "Issue A" has a link to issue "B".

Is it possible to set "Priority" field to "Major" of "issue B", if an user sets "Priority" of "issue A" to "Major"?

I have a chance to use ScriptRunner.

 

2 answers

1 accepted

0 votes
Answer accepted
zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 29, 2018

It can be done by ScriptRunner using the following way:

  1.  System -> Add-ons -> Script Listeners

       2.  Then "Add New Item"

       3.  Then in "Events" we should write : "Issue updated",  and finally paste the follwoing code into "Inline script":

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.IssueManager
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.type.EventDispatchOption;
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.workflow.TransitionOptions


def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)

def issue = event.issue
def idPriorityLoIssue = issue.getPriorityObject().getId().toString();

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sequenceField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Seq."}
log.info(sequenceField)
def sequenceFieldValue = issue.getCustomFieldValue(sequenceField)
log.info(sequenceFieldValue)


def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getOutwardLinks(issue.id).each{ issueLink ->
def linkedIssue = issueLink.getDestinationObject()
log.info('1. ***** LinkedIssue: *****' + linkedIssue)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def issueInputParameters = new IssueInputParametersImpl()
def issueService = ComponentAccessor.getIssueService()
issueInputParameters.setPriorityId(idPriorityLoIssue.toString())
issueInputParameters.setSkipScreenCheck(true)
def validationResult = issueService.validateUpdate(user, linkedIssue.id, issueInputParameters)
log.info('validationResult.isValid() ' + validationResult.isValid())

if (validationResult.isValid()) {
log.info('vaild')
issueService.update(user, validationResult)
log.info('2. ***** Priority of issue is set to: *****' + idPriorityLoIssue)
def seqFieldLinkedIssue = customFieldManager.getCustomFieldObjects(linkedIssue).find {it.name == "Послед."}
if(seqFieldLinkedIssue){
def changeHolder = new DefaultIssueChangeHolder()
seqFieldLinkedIssue.updateValue(null, linkedIssue, new ModifiedValue(linkedIssue.getCustomFieldValue(seqFieldLinkedIssue), sequenceFieldValue),changeHolder)
}
} else {
log.info('not vaild')
log.warn validationResult.errorCollection.errors
log.info('3. ***** Priority of issue is NOT set to: *****' + idPriorityLoIssue)
}
}

 

0 votes
Danyal Iqbal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2018

Yes. Have a look at the documentation for  Script runner (if you can script:).

or attempt the scriptless solution below:

-remove the priority field from the edit screen.

-Create a global transition for set priority and add prioity to the corresponding screen.

-Use the  Copy Field Value To Linked Issues post function from Misc. Workflow Extension plugin.

zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 18, 2018

Thanks for your reply!
How can I do it using ScriptRunner?

Suggest an answer

Log in or Sign up to answer