Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create Jira Issue with groovy script in Insight automation

Hi all, 

I have the following problem. I need to create a Jira-Issue with some Insight-attributes but the insight automation functionality of "create a Jira issue" is not enough (setting approver e.g). So my idea was to create a script which can handle this. I fail already to create a simple Issue. The following script works fine in scriptrunner but it doesn't work as an insight automation.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.fields.config.manager.PrioritySchemeManager

def projectKey = 'Test'
def issueTypeName = 'Service Request VPN'
def reporterKey = 'testuser'

def summary = 'my summary'


final description = """ some text

"""

def issueService = ComponentAccessor.issueService
def constantsManager = ComponentAccessor.constantsManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def prioritySchemeManager = ComponentAccessor.getComponent(PrioritySchemeManager)

def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey)
def issueType = constantsManager.allIssueTypeObjects.findByName(issueTypeName)

 

def reporter = loggedInUser

def issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(project.id)
setIssueTypeId(issueType.id)
setReporterId(reporter.name)
setSummary(summary)
setDescription(description)
}

def validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection

def result = issueService.create(loggedInUser, validationResult)
assert result.valid : result.errorCollection


the following exception will be thrown


AutomationRuleGroovyScriptAction, Unexpected error: No signature of method: com.google.common.collect.RegularImmutableMap$Values.findByName() is applicable for argument types: (java.lang.String) values: [Service Request VPN]
groovy.lang.MissingMethodException: No signature of method: com.google.common.collect.RegularImmutableMap$Values.findByName() is applicable for argument types: (java.lang.String) values: [Service Request VPN]
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
at createJiraIssue.run(createJiraIssue.groovy:51)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:574)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:621)
at com.riadalabs.jira.plugins.insight.services.core.impl.GroovyServiceImpl.evaluate(GroovyServiceImpl.java:86)
at com.riadalabs.jira.plugins.insight.services.automation.action.AutomationRuleGroovyScriptAction.doActionSafe(AutomationRuleGroovyScriptAction.java:99)
at com.riadalabs.jira.plugins.insight.services.automation.action.AbstractInsightAutomationAction.doAction(AbstractInsightAutomationAction.java:107)
at com.riadalabs.jira.plugins.insight.services.automation.rule.impl.AutomationRuleEngineImpl.executeAction(AutomationRuleEngineImpl.java:669)
at com.riadalabs.jira.plugins.insight.services.automation.rule.impl.AutomationRuleEngineImpl.executeActions(AutomationRuleEngineImpl.java:654)
at com.riadalabs.jira.plugins.insight.services.automation.rule.impl.AutomationRuleEngineImpl.matchConditionAndExecuteActions(AutomationRuleEngineImpl.java:453)
at com.riadalabs.jira.plugins.insight.services.automation.rule.impl.AutomationRuleEngineImpl.executeAsConfiguredUser(AutomationRuleEngineImpl.java:261)
at com.riadalabs.jira.plugins.insight.services.automation.rule.impl.AutomationRuleEngineImpl.handleAsyncEvent(AutomationRuleEngineImpl.java:214)
at com.riadalabs.jira.plugins.insight.services.automation.event.AutomationRuleEventListener.onAsyncEvent(AutomationRuleEventListener.java:94)
at sun.reflect.GeneratedMethodAccessor4705.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:87)
at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:144)
at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:72)
at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:34)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

It would be fine if anyone could help me, maybe there is also a different way to create Jira Issue with insight automation to set an approver an other fields with values of insight.

 

1 answer

0 votes

The "findByName" is an extension to the collection method that Adaptavist adds within scriptrunner.

Change it to

def issueType = constantsManager.allIssueTypeObjects.find{it.name == issueTypeName}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM Jira Automation: How to Send SLA Breached Notifications

Hi Everyone, In   this tutorial,  we will show you how you can monitor an SLA, and send notifications before or after the SLA has been breached.   SLA Threshold Trigger The SLA t...

610 views 5 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you