Forums

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

Getting error for getIssueLink method

Parsa Mounika December 19, 2022

Hi Team,

One of our customer provided the script and asked us to implement that in the listeners. While we are implementing it we are getting error as shown in pic. I am sharing the script also can some one check and help me.


Issue destinationIssue = event.getIssueLink().getDestinationObject()
Issue masterIssue = event.getIssueLink().getSourceObject()
Screenshot (17).png

1 answer

0 votes
Ismael Jimoh
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.
December 19, 2022

Hi @Parsa Mounika 

I don’t see you having gotten the issue itself first. Normally I’ll expect event.getIssue and after that you can get the link if you want.

This is also what the error you have at the top is saying.

Parsa Mounika December 19, 2022

Hi @Ismael Jimoh , I am sharing my script can you help me how to make those changes.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent

Issue destinationIssue = event.getIssueLink().getDestinationObject()
Issue masterIssue = event.getIssueLink().getSourceObject()


    def issueLinkManager = ComponentAccessor.getIssueLinkManager()
    def issueManager = ComponentAccessor.getIssueManager()
   ApplicationUser user = ComponentAccessor.getUserManager().getUserByName("sourcingRoadmapBot");
   CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
   CustomField comCF = customFieldManager.getCustomFieldObject(44401) // Get customfield Commitment
 
    issueLinkManager.getOutwardLinks(masterIssue.id).each { link ->
      if (link.getLinkTypeId() == 10161) {
            MutableIssue slaveIssue = link.getDestinationObject() as MutableIssue;
           
            slaveIssue.setPriority(masterIssue.getPriority());
           
            slaveIssue.setCustomFieldValue(comCF,masterIssue.getCustomFieldValue(comCF));
            issueManager.updateIssue(user, slaveIssue, EventDispatchOption.ISSUE_UPDATED, false);
      }
   }


Ismael Jimoh
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.
December 19, 2022

Also why do you have the getissuelink before defining the issuelinkmanager.

I will recommend reviewing the code properly before implementing it.

If the goal is to get the issue the event.getIssue() should suffice just fine.

Thanks.

Ismael Jimoh
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.
December 19, 2022

I can’t as I don’t know what the script is meant for or what the intentions behind the script is.

Say what is the master issue or destination issue? All these have no concrete meaning to me as I don’t know what your original goal is here. From looking simply I can guess you want to update an issue’s priority and some custom field value based on the value from the masterissue.

the closest I can help is order your code:

 
importcom.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
importcom.atlassian.jira.event.type.EventDispatchOption
importcom.atlassian.jira.event.issue.link.IssueLinkCreatedEvent

def issueLinkManager = ComponentAccessor.getIssueLinkManager() 
def issueManager = ComponentAccessor.getIssueManager()
   ApplicationUser user = ComponentAccessor.getUserManager().getUserByName("sourcingRoadmapBot");
   CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
   CustomField comCF = customFieldManager.getCustomFieldObject(44401) // Get customfield Commitment
Issue masterIssue = event.getIssueLink().getSourceObject()// if this is the main issue from the event then event.issue gets you the issue in question. You can replace this with even.getIssue() as well
//Issue destinationIssue = event.getIssueLink().getDestinationObject() not sure this is needed
 
    issueLinkManager.getOutwardLinks(masterIssue.id).each { link ->
      if (link.getLinkTypeId() == 10161) {
            MutableIssue slaveIssue = link.getDestinationObject() as MutableIssue;
           
            slaveIssue.setPriority(masterIssue.getPriority());
           
            slaveIssue.setCustomFieldValue(comCF,masterIssue.getCustomFieldValue(comCF));
            issueManager.updateIssue(user, slaveIssue, EventDispatchOption.ISSUE_UPDATED, false);
      }
   }


Knowing what you are aiming to achieve will help greatly here.
Ismael Jimoh
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.
December 19, 2022

Sorry I’m working from my phone now and eyeballing the code on the fly. I don’t see the need for the destination issue since you are getting the slaveIssue later.

If master issue is the issue that triggers the event then as mentioned the event.getIssue() is the way to go. Similarly, event.issue works here

Suggest an answer

Log in or Sign up to answer