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,463,003
Community Members
 
Community Events
176
Community Groups

Set the Organization using Test Field

Cleaning up imported data, where the Orgnization value was imported into a text field.  We now need to clean this up to get more accurate reports etc.

I've gotten so far with extracting the value, but unbale to set the Organization field, using Script Runner.

enableCache = {-> false}

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.issue.index.IssueIndexingService;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.user.*
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.sal.api.user.UserManager
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.*
import groovy.transform.BaseScript

 

def appUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkManager = ComponentAccessor.getIssueLinkManager()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def issueManager = ComponentAccessor.getIssueManager()
def ScriptLog = Logger.getLogger("Jira Log")
def userManager = ComponentAccessor.getUserManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
log.setLevel(Level.DEBUG)

def currentUser = userManager.getUserByName("JIRA ADMIN")

// def jqlSearch = "\"Company Code (T)\" is not EMPTY AND \"Company Name (T)\" is not EMPTY ORDER BY cf[10610] ASC"
def jqlSearch = "KEY = ALOGS-1538"

def CompanyName = customFieldManager.getCustomFieldObjectsByName("Company Name (T)")
def OrganizationsField = customFieldManager.getCustomFieldObjectsByName("Organizations")

SearchService.ParseResult parseResult = searchService.parseQuery(appUser, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(appUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.results.collect {issueManager.getIssueObject(it.id)}
ScriptLog.info("Issues Found " + issues.size)
issues.each { issue ->
ScriptLog.info("Name: " + issue.getCustomFieldValue(CompanyName))
def mutableIssue = ComponentAccessor.getIssueManager().getIssueObject(issue.getKey());
boolean isIndex = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);

//OrganizationsField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(OrganizationsField), issue.getCustomFieldValue(CompanyName)), new DefaultIssueChangeHolder())

//issue.setCustomFieldValue(OrganizationsField, issue.getCustomFieldValue(CompanyName))
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)

IssueIndexingService IssueIndexingService = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class);
IssueIndexingService.reIndex(mutableIssue);
ImportUtils.setIndexIssues(isIndex);

}
} else {
ScriptLog.error("Invalid JQL :" + jqlSearch)
}
ScriptLog.info("Completed")

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events