Forums

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

How to check whether the screen is the Create linked issue screen using Behaviour. [ScriptRunner]

DOBA Shuzaburo [Ricksoft]
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 16, 2020 edited

I would like to split the process between the Create linked issue screen and the standard Create issue screen using Behaviour.

I have used the getFieldScreen() method.
However, both returned the same a Create issue screen name.

Is there a way to check whether the screen is the Create linked issue screen?

3 answers

2 votes
Reinhard Mayr July 10, 2024 edited

It's a hack, but I think this can be a solution:

I have noticed, that the field order is different between the create issue and the create linked issue forms, because the latter puts the issue link fields right after project and issue type before the summary.

Since the formContents are a LinkedHashMap, which preserves the order of its elements, I can use that information as a criterion in my behavior script:

(updated version)

def keys = getFormContents().keySet().toArray()

if (behaviourContextId == "request-new-analysis") {
    // coming from UI fragment by that name
    log.warn("Create linked issue through UI fragment.")

} else if (keys.findIndexOf { it == "issueId" } < 0) {
    // no issueId found: this seems to be a create screen
    log.warn("create screen")

    if (keys.findIndexOf { it == "summary" } < 0) {
        // no summary field
        log.warn("Create issue form w/o fields.")

    } else if (keys.findIndexOf { it == "issuelinks" } < keys.findIndexOf { it == "summary" }) {
        // issue links are before the summary
        log.warn("Create linked issue form.")

    } else {
        log.warn("Create issue form with fields.")
    }

} else {
    // issueId is present: this is an edit, assign, or transition screen
    log.warn("non-create screen")
}
What do you think?

 

Robert Leachman
Contributor
July 16, 2024 edited

What do I think, it asks? I think this is brilliant!

For this project the Create screen does not feature Linked Issues at all so the code is simple:

 

def creatingLinkedIssue = false;
def keys = getFormContents().keySet().toArray()
if (keys.findIndexOf { it == "issuelinks" } > 0) {
    creatingLinkedIssue = true;
}

Breaks me loose solving the problem we are having, thanks!

Like Reinhard Mayr likes this
1 vote
Mathis Hellensberg
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.
June 18, 2020 edited

Hi @DOBA Shuzaburo [Ricksoft] 

I really tried to accomplish this, but as Scriptrunners webpage describes, there is no possible way of doing what you are asking. As you have found for yourself, it always just returns the create screen even when using getFieldScreen().

"Behaviours function on the Create Issue, Update/Edit Issue, Assign Issue, and Workflow Transition screens.

On the View Issue screen, trying to edit a field with a behaviour launches the Edit Issue screen, instead of the normal inline editor.

Behaviours do not work on the Move Issue screen. They also do not work for any bulk issue operations, or any issue edits that bypass the UI such as the REST API and other ScriptRunner scripts."

秀三郎 道場
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 19, 2020

Dear @Mathis Hellensberg 

Thank you for your answer.

As you said, I found the description on the following page.
https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html#_screens

As I thought, it seems impossible...

Mathis Hellensberg
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.
June 19, 2020

@DOBA Shuzaburo [Ricksoft]  Please accept my answer so others might find it :)

0 votes
秀三郎 道場
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 9, 2020

Test Comment

Suggest an answer

Log in or Sign up to answer