Hi,
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, sounds nice. For now I attached the simple postfunction script to my answer.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.