I have struggled a bit with the ScriptRunner "Constrained Create Issue Dialog" feature and share here my learnings.
Problem Description
I wanted to implement a Custom Action to create an Issue of a specific type derived from an existing issue with a link to the original issue and a customized Description and also taking over/copying a couple of custom fields.
Usually, one would think Exocet Copy&Sync Add-On would be the right tool for this, but I couldn't find a way with it to fill the description field with a customized value (based on a template).
ScriptRunner Create Constrained Issue Feature looks like a good alternative though I faced the following challenges:
- The Create Constrained Issue Feature requires the user to select a project (option is mandatory)
By default, I would like the project to be the same as the original issue (it makes most of the time more sense rather than a hard-coded out-of-context fixed one) - To copy / take over fields from the original issue to the create issue form, it isn't very easy, especially for custom fields like single-select
Change Project to same as original issue
Once one knows it, it is pretty easy to do.
Simply add this line of code to your Behavior Initialiser:
getFieldById(
"project-field"
).setFormValue(contextIssue.projectObject.name)
This will overwrite the fixed Project value in the Script Fragment.
I have contacted the support to get this included in the documentation and considered as a Feature Request (SRJIRA-6012).
Copy Custom Fields
It isn't trivial to copy fields and prefill them in the create form especially because you have to handle different types of fields (like single-select or multi-select, simple text, user, etc.), and to set a field in the form it isn't as easy as setting it to the text value in case of select fields but you need to set the proper optionId.
I couldn't find a standard function to do this and the closest I have found is a snippet in the doc buried under a SubTask example here. I have found it because it was mentioned in this forum discussion.
I have cleaned up the code for my purpose. You can find it here:
https://gist.github.com/tdalon/1578e5e38b68af1a0225df545afa1727
No comments:
Post a Comment