Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

setIssue() is throwing java.lang.NullPointerException when used with WorkflowTransitionUtil workflow

Lipsa Patra March 16, 2023

Hi Team,

With the use of 

WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) ComponentAccessor.getComponent(WorkflowTransitionUtilImpl.class)

setIssue() is throwing java.lang.NullPointerException.

Can someone help with the correct method/value to be passed.

Below is the code used:

import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
 
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller()
//WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) ComponentAccessor.getComponent(WorkflowTransitionUtilImpl.class)

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField epicLink = customFieldManager.getCustomFieldObjectsByName('Epic Link').getAt(0)
MutableIssue parent = (MutableIssue) issue.getCustomFieldValue(epicLink);
if (parent != null) {
    log.warn "${parent.getSummary()}"
    log.warn "${parent.getStatus().getSimpleStatus().getName()}"

    def isDevBacklogStatus = parent.getStatus().getSimpleStatus().getName() in ['New']
    log.warn "${isDevBacklogStatus}"

    if (isDevBacklogStatus) {
        workflowTransitionUtil.setIssue(parent)<----Issue is here
        workflowTransitionUtil.setUserkey(currentUser)
        workflowTransitionUtil.setAction(11)
        if (workflowTransitionUtil.validate()) {
            log.warn "inside validate"
            workflowTransitionUtil.progress()
        }        
    }
}

Regards

Lipsa 

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.
March 16, 2023

Welcome to the Atlassian Community!

The NPE on that line means that the "parent" variable contains a null, not the issue object that the function needs.

So my guess would be that the parent issue the script is running against does not have an Epic link (or the code on the line "MutableIssue parent = ..." is wrong, although it looks ok at a glance to me)

Lipsa Patra March 21, 2023

Hi @Nic Brough -Adaptavist- ,

Thanks for the reply.

Any workaround, do you suggest.?

Regards

Lipsa

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.
March 21, 2023

Don't run the script for issues that do not have an epic link?

Suggest an answer

Log in or Sign up to answer