Forums

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

Scriptrunner: Get Customfield from Parent returns null because of wrong context (Listener)

Patrick Schneider November 30, 2023

Hello,

i want to access a customfield Value from a parent Ticket via a Sub-Task. The CustomField has a configured Context to be only on the parent issue Type (Task).

def subTask = event.issue
def parentIssue = subTask.getParentObject()
def customField = customFieldManager.getCustomFieldObjectByName("my field")
def cfValue = parentIssue.getCustomFieldValue(customField)
Always returns null as result. How can i switch the Context to "Task" to get the value of the field?

1 answer

0 votes
Tansu Akdeniz
Community Champion
December 1, 2023

Hi @Patrick Schneider 

Script seems fine.

Did you do logging to see the values in each line? I believe you got the parentIssue object properly and there is nothing wrong with the customfield naming. Can you double check it? You can also use this id form to be sure.

customFieldManager.getCustomFieldObject("customfield_xxxxx");

Also, please check if cf has a value in parent issue (task).

*I assume you already defined this in your code:

def customFieldManager = ComponentAccessor.getCustomFieldManager();

 

Patrick Schneider December 3, 2023

Hi @Tansu Akdeniz 

yes i checked already. Running the code with hand-coded Parent Ticket and SubTask it works fine, values are there. Just within the Listener it doesn't work, even if it gets the Issues right (SubTask -> Parent Ticket). It cannot access the CF Value (always NULL).

But i already tried to open the Context to the Type *Sub-Task* which suprisingly also returns Null afterwards. I have to say, that the value comes from a CustomField which is provided via the STAGIL Table Plugin. Maybe there is the problem.

Suggest an answer

Log in or Sign up to answer