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

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

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

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! 

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
Community showcase
Published in Jira Service Management

Security Advisory for Jira Service Management

On October 20, 2021, Atlassian published a security advisory for Jira Service Management. The full advisory is available at this link.  We've seen a number of questions already asking for...

76 views 0 1
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