Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • How can i use ScriptRunner for JIRA Cloud to find all issues i moved from Project A to Project B?

Apple Shortcut: Unable to get field from provided name (Due date)

François Rousselet
April 24, 2023

Hello,

I am doing a shortcut to get all my assigned issues and their due date. Unfortunately I am not able to retrieve it.

I tried `due_date`, `Due date` but it doesn't work.

In French, it fails with "La valeur fournie pour Nom du champ dans Obtenir la valeur du champ de ticket n'était pas valide." ('The value provided for Field Name in Get Ticket Field Value was invalid.')

Do you have any idea what field name I am supposed to request?

Thanks!

 

1 answer

0 votes
Bastian Stehmann
Community Champion
June 7, 2018

Hi,

this is a snippet from server, but maybe something like this will work on cloud too.

def String jqlQuery = 'project=B'
def fromProject1 = 'A'
def fromProject2 = 'C'

def result = ''

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def searchService = ComponentAccessor.getComponent(SearchService.class);
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

List<Issue> issues = null

def parseResult = searchService.parseQuery(user, jqlQuery);

if (parseResult.isValid()) {
def searchResult = searchService.searchOverrideSecurity(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.issues
}

issues.each{ Issue issue ->
def oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id)
oldKeys.findAll{it==~/$fromProject1.*/}.each{
result += "$it -> ${issue.key}, "
}
issues.each{ Issue issue ->
def oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id)
oldKeys.findAll(it==~/fromProject2.*/}.each{
result += "$it -> $(issue.key),"
)

Josh Kronick
June 12, 2018

This is what it gives me in the script console when i copied and pasted your code snippet and input the projects..

 

im also not very savvy with scriptrunner, im not greatscript_console1.jpg with groovy, so any help would be GREATLY appreciated.

Bastian Stehmann
Community Champion
June 12, 2018

Hi,

sorry, had some typos in the script that I just fixed and added the imports, please try this again:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter

def String jqlQuery = 'project=B'
def fromProject1 = 'A'
def fromProject2 = 'C'

def result = ''

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def searchService = ComponentAccessor.getComponent(SearchService.class);
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

List<Issue> issues = null

def parseResult = searchService.parseQuery(user, jqlQuery);

if (parseResult.isValid()) {
def searchResult = searchService.searchOverrideSecurity(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.issues
}

issues.each{ Issue issue ->
def oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id)
oldKeys.findAll{it==~/$fromProject1.*/}.each{
result += "$it -> ${issue.key}, "
}
}

issues.each{ Issue issue ->
def oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id)
oldKeys.findAll{it==~/$fromProject2.*/}.each{
result += "$it -> ${issue.key},"
}
}
Josh Kronick
June 13, 2018

for whatever reason, it only has a problem with those first 4 lines of "import" code... see screenshot.

 

Thanks for all your help.script_console_error_log.JPG

Bastian Stehmann
Community Champion
June 13, 2018

Does it work without the imports? Or does it complain then that it does not find the classes in the other lines?

Josh Kronick
June 13, 2018

ok i thought i was getting somewhere, because it ran the query and looked like it was working, but then received this error...

 

see below:

 

script_console_error_log2.JPG

Bastian Stehmann
Community Champion
June 13, 2018

Hmm, thats because it does not find the class Issue, which was in the imports.

I am sorry, I don't know why it does not accept that import that way. This class is also still in the API-Reference.

Maybe someone else does have any idea on this.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events