Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


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!


Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null

Hello, I'm having some difficulty getting some code to work with a specific issue type of "Escalation" to the specific DBA webhook. I've been able to verify with our same slack webhook (removed for obvious reasons) is working and that other issue types are working. Here is the error message followed by the code.



2023-01-19 09:13:50,660 WARN [runner.ScriptBindingsManager]: 
Atl Admin: false
Database Admin: true
Network Admin: false
Sys Admin: false
2023-01-19 09:13:50,660 INFO [runner.ScriptBindingsManager]: Issue Key: EDCO-248989 Issue Type is Escalation
2023-01-19 09:13:50,816 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2023-01-19 09:13:50,816 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null status code: 400, reason phrase: Bad Request
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at org.apache.http.impl.client.CloseableHttpClient.execute(
at org.apache.http.impl.client.CloseableHttpClient.execute(
at$ Source)



import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig


def issue = event.issue as Issue
def typesToExclude = ["Change","Epic","Project Milestone","Project Deliverable (Sub-task)","Request Test"]

if(typesToExclude.contains( { "Not a valid issue for notification"; return }

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
OptionsManager optionsManager = ComponentAccessor.getOptionsManager()

CustomField cfaTeam = customFieldManager.getCustomFieldObject("customfield_14202") // Assigned Team
FieldConfig fcaTeam = cfaTeam.getRelevantConfig(issue)

Option sysa = optionsManager.getOptions(fcaTeam)?.find { it.getValue() == 'Systems Administration' }
Option dba = optionsManager.getOptions(fcaTeam)?.find { it.getValue() == 'Database Administration' }
Option na = optionsManager.getOptions(fcaTeam)?.find { it.getValue() == 'Network Administration' }
Option atl = optionsManager.getOptions(fcaTeam)?.find { it.getValue() == 'Atlassian Administration' }

Option teamOption = issue.getCustomFieldValue(cfaTeam) as Option

def isSysAdmin = sysa == teamOption
def isDba = dba == teamOption
def isNa = na == teamOption
def isAtl = atl == teamOption

def infTeamsList = [isAtl, isDba, isNa, isSysAdmin]

if(!infTeamsList.contains(true)) { log.warn "Not an Infrastructure Team"; return }
log.warn "\nAtl Admin: ${infTeamsList[0] as String}\nDatabase Admin: ${infTeamsList[1] as String}\nNetwork Admin: ${infTeamsList[2] as String}\nSys Admin: ${infTeamsList[3] as String}"

def webhookPath = ''
final webhookPathAtl = '/services/xxxx'
final webhookPathElOne = '/services/xxxxx'
final webhookPathElTwo = '/services/xxxxxx'
final webhookPathElThree = '/services/xxxxxxx'
final webhookPathElLeadership = '/services/xxxxxxxx'
final webhookPathNetworkAdmin = '/services/xxxxxxxxx'
final webhookPathDBA = 'services/xxxxxxxxxx'

if (isAtl) { webhookPath = webhookPathAtl }
else if (isDba) { webhookPath = webhookPathDBA }
else if (isNa) { webhookPath = webhookPathNetworkAdmin }
else if (isSysAdmin)
CustomField cfaEl = customFieldManager.getCustomFieldObject("customfield_19303") // Escalation Level
FieldConfig fcaEl = cfaEl.getRelevantConfig(issue)

Option one = optionsManager.getOptions(fcaEl)?.find { it.getValue() == 'Level 1' }
Option two = optionsManager.getOptions(fcaEl)?.find { it.getValue() == 'Level 2' }
Option three = optionsManager.getOptions(fcaEl)?.find { it.getValue() == 'Level 3' }
Option leadership = optionsManager.getOptions(fcaEl)?.find { it.getValue() == 'Leadership' }

Option elOption = issue.getCustomFieldValue(cfaEl) as Option ?: one

def levelOne = one == elOption
def levelTwo = two == elOption
def levelThree = three == elOption
def levelLead = leadership == elOption

if(levelOne) {
log.debug "Sys Admin level 1 webhook path set"
webhookPath = webhookPathElOne
else if(levelTwo) {
log.debug "Sys Admin level 2 webhook path set"
webhookPath = webhookPathElTwo
else if(levelThree) {
log.debug "Sys Admin level 3 webhook path set"
webhookPath = webhookPathElThree
else if(levelLead) {
log.debug "Sys Admin Leadership webhook path set"
webhookPath = webhookPathElLeadership
else { log.error "Sys Admin detected, but no EL found. No notification sent."; return }

else {
log.error "No Alert Defined"

final webhookBase = ''
def jiraBaseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)

//Issue detail augmentation
String org_summary = issue.summary
String summary = org_summary
String org_description = issue.description ?: ""
String description = org_description.replace("*Description copied from Parent:*","") ?: ""

String textBlock = "${}: <$jiraBaseUrl/browse/$issue.key|${summary}>" "Issue Key: ${issue.key} Issue Type is ${}"

def body = [
text: summary,
blocks: [
type: 'section',
text: [
type: 'mrkdwn',
text: textBlock

def response = new RESTClient(webhookBase).post(
path: webhookPath,
contentType: ContentType.HTML,
body: body,
requestContentType: ContentType.JSON
) as HttpResponseDecorator

assert response.status == 200: "Request failed with status $response.status. $response.entity.content.text"

0 answers

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events