Forums

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

Get Parent issue of issue- post function

Dan27
Contributor
August 22, 2018

Hello,

I tried to make a post function, that copy from the parent (Bug-Internal type) of an issue (QVR type) the value of custom field 'Resolution' .. and insert this value into custom field of the issue 'Reason' (Text field)

 

I didn't success to get the parent at all.. It tell me that I get null.

This is my code, Any ideas how can it works?  ->

 


import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue;

def issueManager = ComponentAccessor.getIssueManager();


def issueLinkManager = ComponentAccessor.getIssueLinkManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
//test
//Issue issue = issueManager.getIssueObject("WBL-57142");

//Get QVR 'Reason' field

CustomField Reason = customFieldManager.getCustomFieldObjectByName("Reason");

//Get Bug-Internal issue
try {
def issueLink = issueLinkManager.getOutwardLinks(issue.getId());
//Get key of linked issue="is Bug Of QVR"
def key=issueLink[0].getDestinationObject();
key=key.toString();

//Get Bug linked issue
Issue Bug = issueManager.getIssueObject(key);
log.warn Bug;


//Get resolution value
def ResolutionField = Bug.getResolution().name;
log.warn ResolutionField


//update 'Reason' field of issue
def changeHolder = new DefaultIssueChangeHolder();
Reason.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(Reason), ResolutionField),changeHolder);

} catch (e) {
log.warn e.message;
}

1 answer

0 votes
Mark Markov
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 22, 2018

Hello @Dan27

What is relation between "Bug-Internal type" and "QVR type"

Are they just linked or have task : sub-task relation?

If second, you ll need to use

def parent = issue.getParentObject()
Dan27
Contributor
August 22, 2018

Hi @Mark Markov ,

They are linking..

Dan27
Contributor
August 26, 2018

@Mark Markov How can I write the script if they are linking ?

Mark Markov
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 28, 2018

Find an error in your code. getDestinationObject() method returns Issue object, so you dont need to get it later. Try like this

import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue;

def issueManager = ComponentAccessor.getIssueManager();


def issueLinkManager = ComponentAccessor.getIssueLinkManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
//test
//Issue issue = issueManager.getIssueObject("WBL-57142");

//Get QVR 'Reason' field

CustomField Reason = customFieldManager.getCustomFieldObjectByName("Reason");

//Get Bug-Internal issue
try {
def issueLink = issueLinkManager.getOutwardLinks(issue.getId());
//Get key of linked issue="is Bug Of QVR"
def bug =issueLink[0].getDestinationObject();
//key=key.toString();

//Get Bug linked issue
//Issue Bug = issueManager.getIssueObject(key);
log.warn bug;


//Get resolution value
def ResolutionField = bug.getResolution().name;
log.warn ResolutionField


//update 'Reason' field of issue
def changeHolder = new DefaultIssueChangeHolder();
Reason.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(Reason), ResolutionField),changeHolder);

} catch (e) {
log.warn e.message;
}
Dan27
Contributor
August 28, 2018

Thank @Mark Markov ,

It wrote for me this error: 

Cannot invoke method getDestinationObject() on null object
Mark Markov
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 28, 2018

This means that issue doesnt have any outward links.

May be link inward?

try 

def issueLink = issueLinkManager.getInwardLinks(issue.getId());

instead of

def issueLink = issueLinkManager.getOutwardLinks(issue.getId());
Dan27
Contributor
August 28, 2018

I tried it already , It is link outward.. does not work..

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events