Hello guys,
I use Data center Jira instance, version 9.12.13.
I have a scriptrunner custom script, that creates a new project by copying from existing project and setting specific project category.
Script:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.jira.groovy.MyScript")
def projectManager = ComponentAccessor.projectManager;
def projectId = issue.getCustomFieldValue("Projektové šablóny");
def adminUser = 'JiraAdmin'
def sourceKey = projectManager.getProjectObj(projectId as Long).key
def targetKey = issue.getCustomFieldValue("Kód projektu");
def targetName = issue.getCustomFieldValue("Názov projektu");
def projectCreationError = "Chyba pri vytváraní projektu. Kontaktujte Jira Administrátora"
def projectCreationSuccess = "Projekt vytvorený úspešne"
def projectCreationInputError = "Konfigurácia vytvorenia projektu obsahuje chyby:"
def projectCategorySet = "Aktualizácia kategórie projektu"
def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT): sourceKey,
(CopyProject.FIELD_TARGET_PROJECT): targetKey,
(CopyProject.FIELD_TARGET_PROJECT_NAME): targetName,
(CopyProject.FIELD_COPY_VERSIONS): false,
(CopyProject.FIELD_COPY_COMPONENTS): false,
(CopyProject.FIELD_COPY_ISSUES): false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS): false
]
def errorCollection = copyProject.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
log.error(projectCreationInputError + " $errorCollection")
throw Exception(projectCreationInputError + " $errorCollection")
}
log.warn("Validation passed")
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(ComponentAccessor.userManager.getUserByName(adminUser))
copyProject.doScript(inputs)
def newProject = ComponentAccessor.projectManager.getProjectObjByKey(targetKey)
if (!newProject) {
log.error(projectCreationError)
throw new Exception(projectCreationError)
}
log.warn(projectCreationSuccess + " $targetKey: $targetName")
def projectCategory = projectManager.getProjectCategoryObjectByName('Implementačný projekt')
projectManager.setProjectCategory(newProject, projectCategory)
log.warn(projectCategorySet)
New project is copied from the project specified in projectId variable, that gets value from field "Projektové šablóny" (sorry for non-english language:)), that is a custom project picker:
I get a name for new project from "Názov projektu" and new project key from "Kód projektu".
The script is executed successfully. New project is created (with new name and project code):
But, when I want to go to the project details, I get an error (you can see that the projectKey is correct):
And here funny things happen.
return ComponentAccessor.getProjectManager().getProjectByCurrentKeyIgnoreCase("TPD").getId()the result is the ID of project.
return ComponentAccessor.getProjectManager().getProjectByCurrentKey("TPD")
also returns result "Project: TPD"
When using
return ComponentAccessor.getProjectManager().getProjectObjByKey("TPD")
this returns NULL.
So to sum it up - I create a new project using scriptrunner custom script and "CopyProject" functionality. The script creates a project, but the project is not accessible (returns error, that project cannot be found with project key) until I change some details like "Name", "Key", "Avatar" (that are available in "Projects" tab in "Admin" section.
No idea why this is happening.
I'll be glad to hear any suggestions.
Thank you in advance.
PS: Sorry for long post, just wanted to give you all the information.
Refresh method of project manager does the job.
Hi @Pavol Gočal
When copying the issues from one project to another, have you tried using the Built-in Script for ScriptRunner for Jira Cloud, i.e. Bulk Clone Issues?
Let me know how it goes.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Shiva Kumar Hiremath
Reindexing was one of the things I tried and it did not help. Forgot to mention it in the main post.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @pavol,
I think Reindexing jira might resolve the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.