is it possible to have a listener define a projectKey from whatever project a event is triggered by?

Alex Sprague February 24, 2021

is it possible to have a listener define a projectKey from whatever project a event is triggered by?

 

Below is a script i put together for auto distance calculations that i need to deploy to all of my projects. As of now i am constrained by the projectKey = 'XCAT' 

Is there any way to define the projectKey based on whatever project the issue that triggers this event belongs to. in this case any time a issue is created or a issue is updated i want this to fire across all projects.

 

// get custom fields
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>

def input1CfId = customFields.find { it.name == 'Footage' }?.id
def outputCfId = customFields.find { it.name == 'Mileage' }?.id
def projectKey = 'XCAT'

if (issue == null || ((Map)issue.fields.project).key != projectKey) {
logger.info("Wrong Project ${issue.fields.project.key}")
return
}

def input1 = issue.fields[input1CfId] as Integer
def output = 0
if (input1 != null) {
output = input1 /5280
}

if(input1 == null){
output = null
}

put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output
]
])
.asString()

1 answer

1 accepted

1 vote
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 24, 2021

Hi @Alex Sprague what event is used to trigger the listener? Is it issue updated? If so, you could use:

def projectKey = issue.fields.project.key

You can find some examples here: https://scriptrunner-docs.connect.adaptavist.com/jiracloud/script-listeners.html#_examples 

Alex Sprague February 25, 2021

@Martin Bayer _MoroSystems_ s_r_o__ The event triggers are issue updated and issue created. Thank you for your quick reply! 

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 25, 2021

Hi @Alex Sprague you are welcome, but did my information help or you need more information? :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events