Hello,
I have enabled a post function to run a script get value from Custom Fields and create project automatically.
Script :-
import com.atlassian.jira.bc.project.ProjectCreationData
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.AssigneeTypes
import com.atlassian.jira.project.type.ProjectTypeKey
import org.apache.log4j.Logger
import org.apache.log4j.Level
def logg = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
logg.setLevel(Level.INFO)
// the key for the new project from custom field
def projectKey = "Project Key"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def projectKeyV = customFieldManager.getCustomFieldObjectByName(projectKey)
def getKeyV = issue.getCustomFieldValue(projectKeyV)
log.info("The Key is" + getKeyV )
// the name of the new project
def projectName = "Project Name"
def projectNameV = customFieldManager.getCustomFieldObjectByName(projectName)
def getNameV = issue.getCustomFieldValue(projectNameV)
log.info("The Key is" + getNameV )
def projectService = ComponentAccessor.getComponent(ProjectService)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// available project type keys: business | software | service_desk
def projectTypeKey = new ProjectTypeKey("software")
def creationData = new ProjectCreationData.Builder().with {
withName(getNameV)
withKey(getKeyV)
withLead(loggedInUser)
withUrl(null)
withAssigneeType(AssigneeTypes.PROJECT_LEAD)
withType(projectTypeKey)
}.build()
final ProjectService.CreateProjectValidationResult projectValidationResult = projectService.validateCreateProject(loggedInUser, creationData)
assert projectValidationResult.isValid() : projectValidationResult.errorCollection
projectService.createProject(projectValidationResult)
I am getting an error when I am running this script
Error:-
ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue JIRA-1731 for user 'Sunilkumar'. workflowMode=live&workflowName=New+JS+Workflow&descriptorTab=postfunctions&workflowTransition=481&highlight=1
java.lang.AssertionError: Errors: {projectType=An invalid project type was specified. Make sure the project type is available in your Jira instance. Please talk to your Jira administrator if you need more help.}
Error Messages: []. Expression: projectValidationResult.isValid()
at Script111.run(Script111.groovy:44)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:174)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$3.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:293)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$2.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScript(AbstractScriptRunner.groovy:305)
at com.onresolve.scriptrunner.runner.ScriptRunner$runScript$10.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.utils.TypedCustomScriptDelegate.execute(TypedCustomScriptDelegate.groovy:19)
at com.onresolve.scriptrunner.canned.jira.utils.TypedCustomScriptDelegate$execute$0.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction.execute(CustomScriptFunction.groovy:53)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction$execute.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.workflow.AbstractWorkflowCannedScript.execute(AbstractWorkflowCannedScript.groovy:20)
at com.onresolve.scriptrunner.canned.jira.workflow.AbstractWorkflowCannedScript$execute$1.call(Unknown Source)
at com.onresolve.scriptrunner.jira.workflow.AbstractScriptWorkflowFunction$_run_closure2.doCall(AbstractScriptWorkflowFunction.groovy:89)
at com.onresolve.scriptrunner.jira.workflow.AbstractScriptWorkflowFunction$_run_closure2.doCall(AbstractScriptWorkflowFunction.groovy)
at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy:350)
at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy)
at com.onresolve.scriptrunner.runner.ScriptExecutionRecorder.withRecording(ScriptExecutionRecorder.groovy:13)
at com.onresolve.scriptrunner.runner.ScriptExecutionRecorder$withRecording.call(Unknown Source)
at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl.execute(DiagnosticsManagerImpl.groovy:348)
at com.onresolve.scriptrunner.runner.diag.DiagnosticsExecutionHandler$execute$3.call(Unknown Source)
at com.onresolve.scriptrunner.jira.workflow.AbstractScriptWorkflowFunction.run(AbstractScriptWorkflowFunction.groovy:82) Regards,
Sunil