Determine is screen opened is an Edit screen

Aleksandr Serebriakov November 9, 2017

Messing with Behaviors....

What I am trying to do is to determine is a currently opened screen is an Edit screen.
As I see it, I have to get a current screen scheme and screen id assigned as an Edit screen in it.
Then I have to get a currently opened screen id and compare them.

Googled it a lot ad tried dozens of code examples, but keep bumping on basically the same kind of dead ends. Either I cant get current issue id (what is needed in one kind of code), or I get something like this:


groovy.lang.MissingPropertyException: No such property: IssueOperations for class:

 

The Goal is to determine is opened screen is an Edit screen. Maybe the is an other way to do that.

4 answers

1 accepted

0 votes
Answer accepted
Alexey Matveev
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.
November 9, 2017

Hello,

The code would be like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.operation.IssueOperations

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("issuekey");
def screen = ComponentAccessor.getIssueTypeScreenSchemeManager().getFieldScreenScheme(issue).getFieldScreenSchemeItem(IssueOperations.EDIT_ISSUE_OPERATION )

log.error("eidt screen id" + screen.getId())

Or

import com.atlassian.jira.component.ComponentAccessor
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("issuekey");
def screen = ComponentAccessor.getIssueTypeScreenSchemeManager().getFieldScreenScheme(issue).getFieldScreenSchemeItems().find {
it.getIssueOperationName() == "admin.issue.operations.edit";
}

log.error("eidt screen id" + screen.getId())

 

Aleksandr Serebriakov November 9, 2017

Hello Alexey,

Once again you are helping me out :)

The first code doesn't work in my situation because using code in the Behaviors the last one could not import "...operation.IssueOperations", so IssueOperations.EDIT_ISSUE_OPERATION can't be used:

groovy.lang.MissingPropertyException: No such property: IssueOperations for class: Script1

The second one with a bit of modification does what I need. In situation with Behaviors, to get an issue object/key we have to use:

def issueId = formContents["id"]
def issueOBJ = ComponentAccessor.getIssueManager().getIssueObject(issueId as Long)

// or

def issueOBJ = getUnderlyingIssue()

 

Lyrical digression...
I thought that if I'll get an IssueOperationName it would be equivalent to "IssueOperations.EDIT_ISSUE_OPERATION", and if I'll put it into getFieldScreenSchemeItem() I would get what I want. So I started to play with loops trying to fetch info i need.

def VAR_1 = scrscheme_1.getFieldScreenSchemeItems()
VAR_1.each {
log.debug (" ")
log.debug (" IT " +it)
if(it.getIssueOperation()){
log.debug (" OPERATION ID " +it.getIssueOperation().getId())
log.debug (" OPERATION KEY " +it.getIssueOperation().getNameKey())
log.debug (" OPERATION DEC " +it.getIssueOperation().getDescriptionKey())
log.debug (" OPERATION NAME " +it.getIssueOperationName())
}
}

I was wrong.

But it gave me a thought that from that loop I сan get what I need by taking an IssueOperation with the name I need ("admin.issue.operations.edit").
I was close :) Thank you for saving my time :)

Alexey Matveev
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.
November 10, 2017

You are welcome :)

Aleksandr Serebriakov November 10, 2017

I've just understood, that this code:

def screen = ComponentAccessor.getIssueTypeScreenSchemeManager().getFieldScreenScheme(issue).getFieldScreenSchemeItems().find {
it.getIssueOperationName() == "admin.issue.operations.edit";
}

 returns an "Item" (...getFieldScreenSchemeItems().find...)

and

screen.getId() 

returns an ID of that item.
So to get a Screen ID we need to use:

screen.getFieldScreenId()

 

0 votes
Aleksandr Serebriakov November 10, 2017
0 votes
Aleksandr Serebriakov November 10, 2017

DUPLICATE OF THIS COMMENT

Alexey Matveev
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.
November 10, 2017

What Jira version do you use?

Aleksandr Serebriakov November 10, 2017

6.2.4

Alexey Matveev
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.
November 10, 2017

This is strange. I tested my code in a behavour but my version is 7.2.3

And I had a look in the Api reference this class is available in your Jira version

Aleksandr Serebriakov November 10, 2017

Yes it is (atleast it has to be...), I've checked atlassian docs (docs.atlassian.com/jira/6.2.4/) and it is there, but when I try to import it at behaviors script

import com.atlassian.jira.issue.operation.IssueOperations

I get

Compilation failure: startup failed: Script1.groovy: 6: unable to resolve class com.atlassian.jira.issue.operation.IssueOperations @ line 6, column 1. import com.atlassian.jira.issue.operation.IssueOperations ^ 1 error
Alexey Matveev
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.
November 10, 2017

I ll have a look if a docker image is available for your Jira version, I ll pull it and try at home

Aleksandr Serebriakov November 10, 2017

Ok, thank you. Besides it happens and with other classes for example:

import com.atlassian.jira.issue.fields.screen.FieldScreenManager
import com.atlassian.jira.issue.fields.screen.FieldScreen
Aleksandr Serebriakov November 10, 2017

Just checked my current jira instance and downloaded same version from atlassian. Well these classes are missing in 6.2.4 version.
I wonder what will happen if I'll just put them from newer jira version.
In theory nothing bad should happen instantly, because if they are missing, means jira does not use them. The should not be any code in jira wich would rely on these missing classes.
The interesting part should start when I'll try to use them in a script....
Well... :)

Alexey Matveev
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.
November 10, 2017

Just do not do it in production :)

Aleksandr Serebriakov November 10, 2017

Challenge accepted! :D
Just kiding, I'm too chickenshit to do it in production :)

I'm little confused... and I'm definitely looking for these classes in a wrong place, because I thought they all should be placed in:
atlassian-jira\WEB-INF\classes\com\atlassian

IssueOperations
atlassian-jira\WEB-INF\classes\com\atlassian\jira\issue\operation

FieldScreen
FieldScreenManager
atlassian-jira\WEB-INF\classes\com\atlassian\jira\issue\fields\screen

etc.


But these directories (in any version of jira I've dowloaded 6.2.4-7.5.2) does not contain any of *.class which I am looking for (there are other classes in these dirs, but not the ones I need).
So I gess they are present in some other form (inside of some *.jar, etc.)

UPDATE:

It was ScriptRunner v3.0.5 issue. When I updated it to v3.0.16 it resolved the problem with certain *.class import.

Alexey Matveev
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.
November 12, 2017

Nice to hear. Good job. 

0 votes
Aleksandr Serebriakov November 9, 2017

So I managed to get Screen scheme

import com.atlassian.jira.component.ComponentAccessor

def scrscheme = ComponentAccessor.getIssueTypeScreenSchemeManager()getFieldScreenScheme(getUnderlyingIssue())

 

Now I have to get Operation Screen. Something like:

scrscheme.getFieldScreen(IssueOperation issueOperation)

But how can I specify, for example EDIT screen?

IssueOperation issueOperation

Suggest an answer

Log in or Sign up to answer