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()
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
@Martin Bayer _MoroSystems_ s_r_o__ The event triggers are issue updated and issue created. Thank you for your quick reply!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alex Sprague you are welcome, but did my information help or you need more information? :)
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.