Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner Behaviour on Create Issue Screen

Lukasz Grobelny
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 9, 2023

Quick question - is it possible to control Create Issue Screen by Scriptrunner behaviours on - prem like this:

I'm creating an issue from within epic

I'd like to have some values (summary for example) prepopulated from the epic

 

Just like forms on Service Management where by script we can prefill some values

1 answer

1 accepted

4 votes
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 9, 2023

I generally like to examine the call from my developer panel.

Specifically, when your Create Issue in Epic screen loads, you should see a call to /rest/scriptrunner/behaviours/latest/validatorsByPid.json.

If you examine the outgoing payload, that will give you a clue as to what information your initialiser script will have access to.

Unfortunately, you will see that at the moment, scriptrunner doesn't send what will ultimately be added to the "Epic Link" field unless that field is listed on your screen.

So, if you want a behaviour that's based on the parent epic you have to add the Epic Link to your create screen.

Then, you will see that the parent epic is available as part of the customfield in the payload.

So that means we can write a script with it, but strangely, the value include the prefix "key:". So we'll need to be a little creative.

Here is a snippet that will set the new issue's summary to same as the parent epic, adjust as needed:

 

if(underlyingIssue) return //don't default values during subsequent edits
def
sumFld = getFieldById('summary')
def epicFld = getFieldByName('Epic Link')

if(!epicFld.value) return //there is no value in the Epic Link field or it was not included in the screen

//extract the key from "key:ABC-123"
def
epicKey = (epicFld.value as String).tokenize(':')[1]

//get an issue object
def epicIssue= Issues.getByKey(epicKey)

//do the behaviour actions needed
sumFld.setFormValue(epicIssue.summary)
Lukasz Grobelny
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 10, 2023

And that's a great place to start, thanks!

Suggest an answer

Log in or Sign up to answer