Is it possible to create a groovy script and passed arguments to it into a post function ?
For example, I would like make a script to initialize a date custom field. The script will be "InitializeDate.groovy"
And I define the name of the custom field in the post function that call the script, something like :
\var\initializeDate.groovy "Start Date"
i thought the string "Start Date" could be retrieved with a "$1" argument in the script, it doesn't run.
You could use the attached (SimplePostfunction.groovy.txt) "simple scripted post function" script and use this to call methods from your other scripts. Remove the .txt at the end and put it into the directory according to the package.
Jamie, is there a reason why there is not builtin simple scripted post function? I created one some time ago, but I thought there maybe a reason why you don't included something similar.
No reason, next major release will have the ability to point to a file or use an inline script. Basically everything will be a built-in script, but one of them will be a CustomRunWhateverYouWant type thing.
The simple validator has slightly more logic, in that it handles the validation error.
Put that logic into the script. Rather than adding the field name to the workflow, in your script you can say "if workflow or issue type is X, then initialise date Y".
Alternatively you can read status or transition properties from your script.
It isn't exactly that I want.
In fact, I'm dependent of other teams to put groovy files on Jira server. I would like avoid to call them each time I need use same functionnality on other fields.
In this case, I would like create a script to initalize a Date and Time field with the current date, and call a script with 2 parameters: the name of the concerned field and a parameter to set the comportment if field is already filled.
And I would like be able to call this script in workflow transition each time I need customize a new workflow.
But I understand from your answer that it isn't possible, is it?
@Jamie Echlin [Adaptavist] You mention: "Alternatively you can read status or transition properties from your script." I am trying to figure out how to read a value from a transition property, yet I cannot seem to locate an example or API reference to get me there. Do you happen to have an example of how to read a transition property (key, value pair) within a .groovy file (to be run by Script Runner)?
ComponentAccessor.getWorkflowManager().getWorkflow(issue).getDescriptor().getAction(transientVars['actionId']).getMetaAttributes() That will give you the extra properties you define in the workflow, if that's what you mean. That's just sample code, I wouldn;t actually write it like that.
Thank you @Jamie Echlin [Adaptavist] ! This is exactly what I needed. Example code for retrieving Workflow Transition Properties: import com.atlassian.jira.ComponentManager ComponentManager componentManager = ComponentManager.getInstance() def myTransitionProperty = componentManager.getWorkflowManager().getWorkflow(issue).getDescriptor().getAction(transientVars['actionId']).getMetaAttributes().MyTransitionProperty
Badges are a great way to show off community activity, whether you’re a newbie or a Champion.Learn more
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG