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

What's passed into a Post Function?

Is there a list of parameters that are passed into a Post Function?  I assume that an Issue object is.  Anything else?

Can you pass parameters to a Post Function in addition to those listed above?

For example, we'd like the same "block" of code to do 2 related things but control the behavior by a parameter.

4 answers

1 accepted

0 votes
Answer accepted

There's no place in Jira to pass in parameters to a post-function.

The code in a post-function has access to the whole internal Jira API and gets the "mutable issue" object representing the issue being transitioned and the session data from the account making the transition, but that's all.  If you want other data, your code will have to fetch it.

Thanks, @Nic Brough {Adaptavist}

Where would be one of the locations that that data could be fetched from?

For example, we have Groovy code to get/set the value of a Custom Field.  It's essentially the same code with only the name of the Custom Field different.  We were hoping to pass the Custom Field name in as a parameter.

There doesn't seem to be an easy way to solve this problem with Jira/ScriptRunner (or my perspective isn't wide enough - I'm open to suggestions). 

Thanks, Nic.

You can fetch from anywhere really.  Workflow functions are all aware of the issue being worked on (and hence most of the system fields directly held on them like summary, resolution, type etc), but you can go fetch custom-fields for them as well.

But there is nowhere to store your parameters.  If you want the same post-function to behave differently given different data, you have to put the code that makes that decision into the post-function.

You could easily do something like "if issue type X, then read custom-field-a, else read custom-field-b".  But there's nowhere to store "my parameter".   The closest I can get to a parameter is a workflow or transition property, but that's still going to be hard-coded to the transition in the workflow.

Thanks, @Nic Brough {Adaptavist}

But that means that they all have to be inline scripts rather than stored in files on the server.  I can customize the inline scripts by having internal variables to change behavior but if I did that with files, I'd end up with hundreds of separate files and it would be a mess, hence the reason I was asking for parameters that I could pass into (code in a file).

I am a bit lost on what you mean there. 

There is no difference between an inline script and a file based script - when one is called, Jira reads the script from a field or from a file.  It's the same block of text however you do it.

There is nothing to stop you reading a file in a script, but it won't contain "parameters" from the Jira process, unless you wrote it out in a previous post-function, which is pointless, you might as well just work out what goes into it at the start of the script and not bother writing it, just use the data direct.

@Bruce Mohler 

There is no problem in working with files, when you call a postfunction you it has access to every field that is defined in the issue, you can create a field called parameter or something like that and you give it the value in the issue (I guess your parameters will be based in issuetype, component, version, project or some other data that you have in the issue your are working with so you could easily automate those fields value somewhere in the workflow)

@Bruce Mohler ,

Are you developing your own post function ? 

You can pass any parameter to the post function. You can configure while adding the post function. 

Using plugin factory , you can configure the required parameters.

You can refer below link

https://developer.atlassian.com/server/jira/platform/creating-workflow-extensions/

@Sreenivasaraju P I looked at that creating-workflow-extensions page and it is so far beyond where I'm at that it wasn't much help.  In addition, I didn't see any reference to passing parameters into a Post Function in an Inline Script.

We're looking for functionality that works a bit like passing arguments to a shell script or C program where they can be processed via argc and argv.

with script runner you can access every custom field defined in the scope of the project (usually almost everyone).

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject(xxxxx) //being xxxxx the id of the field

// or
// def cField = customFieldManager.getCustomFieldObjectByName('custon field name')

def cfValue = cField.getValue(issue)

//or
// def cfValue = issue.getCustomFieldValue(cField)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

245 views 1 2
Join discussion

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