Forums

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

Not able to fetch parent object in scriptrunner post function

Deleted user May 24, 2022 edited

Hi,

I need to fetch parent custom field value to compare with sub-task field value . To achieve that I was writing below code in sub task post function but no luck in getting parent issue . Getting null for below tried option . Kindly help to fix the issue in the code.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager;

Issue parentIssue = issue.getParentObject()
log.error("parentIssue = "+parentIssue) -->getting null

def parentId = issue.getParentId();
log.error("parentId = "+parentId) -->getting null

def parent = ComponentAccessor.getIssueManager().getIssueObject(parentId)

log.error("parent = "+parent) -->getting null

def myfieldName = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("myfield").first()
log.error("myfield = "+myfieldName)

def parentValue = parentIssue.getCustomFieldValue(myfieldName )
log.error("parentValue = "+parentValue) 

def parentValue11 = parent.getCustomFieldValue(myfieldName )
log.error("parentValue11 = "+parentValue11)

def Mounts = customFieldManager.getCustomFieldObject("customfield_20610")


log.error("Mounts = "+Mounts.getValue(issue))

 


1 answer

0 votes
Nic Brough -Adaptavist-
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.
May 24, 2022

.getParentObject() will return null if the current issue is not a sub-task, but it mght also be that it can't render the object directly as plain text in your error message.  Try  issue.getParentObject().getKey() for the issue key in plain text.

Suvidhaa M S May 25, 2022 edited

Hi @Nic Brough -Adaptavist- 

Yes. It is not a sub-task, it is a linked issue. Could you please tell us how to retrieve the custom field value from linked issue and compare that value against the custom field value in current issue?

For example.,

Issue A - field AA

Issue B - field BB

Issue A is linked to Issue B. I want to compare field AA and field BB. Kindly help us in providing the code for the same

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events