per-project data in a Post Function

Greg Pflaum
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 18, 2019

I have a script derived from https://library.adaptavist.com/entity/send-custom-notification-to-slack, but for Microsoft Teams. Works fine when run in ScriptRunner console.

I want to use the script as a Post Function in a workflow that is used by many projects. I want to use a different url for each project, e.g. for an event in Jira project X the script posts to the url for Teams project X', and for an event in Jira project Y the script posts to the url for Teams project Y'.

I was hoping to use a per-project attribute to store the URL, and read it from the post function. But I see from https://community.atlassian.com/t5/Jira-Software-questions/custom-field-in-project-details/qaq-p/1182450 there are no project-level custom attributes. I could keep a table of project-to-url mappings in the script. Are there any good alternatives to doing that?

I'm new to Jira and ScriptRunner.

Thanks,
Greg

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 12, 2020

You could store the url in the description of each project using some html tag (so that the url doesn't show when viewing the project) and use some string manipulation or regular expression to extract the URL.

Or you could use the OfBizProperty system. But with that, you will need to use some scripting to store the url for each project (not very user-friendly unless you build a UI too).

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.core.ofbiz.util.OFBizPropertyUtils

def project = ComponentAccessor.projectManager.getProjectObjByKey('JSP')

//initialize the properties for a proeject
def properties = OFBizPropertyUtils.getCachingPropertySet('Project',project.id)

//store the property
properties.setString('msteamworks.url', 'https://someteamworksurl.com/')

//retreive a property
def url = properties.getString('msteamworks.url')
Greg Pflaum
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 12, 2020

Thank you!

Suggest an answer

Log in or Sign up to answer