Following script has stopped working following 7.3 upgrade, any idea why shows error against def componentValue line

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
 import com.atlassian.jira.issue.ModifiedValue
 import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
 import com.atlassian.jira.ComponentManager
 import com.atlassian.jira.bc.project.component.ProjectComponent
MutableIssue myIssue = (MutableIssue) issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def deviceName = customFieldManager.getCustomFieldObjectByName("Device");
def componentValue = myIssue.getComponents()?.first()?.get("name")
 def changeHolder = new DefaultIssueChangeHolder();
deviceName.updateValue(null, myIssue, new ModifiedValue(issue.getCustomFieldValue(deviceName), componentValue), changeHolder);

1 answer

What namely this script should to do? 

What is type for custom field "Divice"?

Device is a text field.

Purpose is to copy the first item in the component/s field to the Device field.

It works correctly in JIRA 6.4.13 but fails when I have upgraded to JIRA 7.3.0

I assume that this code for postfunction. Since try this

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.component.ComponentAccessor

try {
    issue.setCustomFieldValue(
            ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Device")
            , issue.getComponentObjects().iterator().next().getName()
    )

    ComponentAccessor.getIssueManager().updateIssue(
            ComponentAccessor.getJiraAuthenticationContext().getUser()
            , issue
            , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build()
    )
}catch (NullPointerException e){
    if(issue.getComponentObjects().iterator().hasNext())
        throw e;
}

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

239 views 0 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot