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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,558,751
Community Members
 
Community Events
184
Community Groups

script runner cannot invoke method get value () on a null object

 

 

Getting this error (see attachment) when trying to run this script (see below). Can anyone advise. 

 

import com.onresolve.scriptrunner.runner.customisers.PluginModule;
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
@WithPlugin("com.atlassian.teams")
@PluginModule GeneralTeamService teamService;

import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.index.IssueIndexingService;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.rm.teams.api.team.GeneralTeamService;
import com.atlassian.rm.teams.core.team.data.DefaultTeam;

import org.apache.log4j.Logger
import org.apache.log4j.Level

// Set-up the logging.
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)

// Set this variable to enable/disable dry run.
def DRY_RUN = false

// Update the filter of issues that we want to update.
def queryString = "(project = NR OR project = NEWRELIC) AND Team = 166";

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser);
def searchService = ComponentAccessor.getComponent(SearchService);
def optionsManager = ComponentAccessor.getComponent(OptionsManager);
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.issueManager;

def reIndexIssue(Issue issue) {
    boolean wasIndexing = ImportUtils.isIndexIssues();
    ImportUtils.setIndexIssues(true);
    def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService);
    issueIndexingService.reIndex(issue);
    ImportUtils.setIndexIssues(wasIndexing);
}

def teamField = customFieldManager.getCustomFieldObjectsByName("Team").first();
def gmField = customFieldManager.getCustomFieldObjectsByName("GM Group").first();

def query = jqlQueryParser.parseQuery(queryString);

def search = searchService.search(currentUser, query, PagerFilter.getUnlimitedFilter());

def count = 0

search.results.each{documentIssue ->
    def issue = issueManager.getIssueObject(documentIssue.id);

    // Get team value for this ticket.
    def teamValue = issue.getCustomFieldValue(teamField)
    if (!teamValue) {
        return;
    }
    def teamName = teamValue.getDescription().getTitle()

    // Extract the GM group implied in the name `GM -> Team`
    def splits = teamName.split(" -> ")
    if (splits.size() < 2) {
        return;
    }
    def inferredGmGroup = splits[0]

    def currentGmGroup = issue.getCustomFieldValue(gmField).getValue()

    if (currentGmGroup.equals(inferredGmGroup)) {
        // Ticket is already correct.
        return;
    }
   
    count++
   
    // Update the GM Group field in the ticket
    if (!DRY_RUN) {
        def gmConfig = gmField.getRelevantConfig(issue)
        def gmOptions = optionsManager.getOptions(gmConfig)
        issue.setCustomFieldValue(gmField, gmOptions.getOptionForValue(inferredGmGroup, null))
        ComponentAccessor.issueManager.updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
        reIndexIssue(issue)
    }
}

log.debug("Issues updated: " + count)image.png

1 answer

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 03, 2022

There are two things it might be - 

getValue is not a valid call to make on the object being returned by the previous function (which is getCustomFieldValue)

The value in the field is null (the field is empty)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events