Determine is screen opened is an Edit screen

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 vote

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())

 

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 Community Champion Nov 10, 2017

You are welcome :)

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()

 

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
Alexey Matveev Community Champion Nov 10, 2017

What Jira version do you use?

Alexey Matveev Community Champion Nov 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

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 Community Champion Nov 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

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

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 Community Champion Nov 10, 2017

Just do not do it in production :)

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.

Nice to hear. Good job. 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

384 views 4 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you