Why Behaviour script not launching the Edit screen

Ferenc Ghido May 22, 2019

Hi all,

I am using JIRA 7.6.9 and ScriptRunner 5.5.5 and I need to restrict (make mandatory and after read only) the Fix Version/s field after a certain state for Users but editable for project Administrators. The field is available in the Edit and the View screen as well and JIRA instance is set ON for INLINE edit mode.

I created a behaviour and when I change the value of the Fix Version/s field in View screen the behaviour is not lauching the Edit screen hence I can modify the Value without any restriction.

Same applies for other custom fields :(

If I am opening the Edit screen the behaviour is working as expected.

Can someone help me why the behaviour not launching the Edit screen when I click to the field in View screen ?

 

Example:

  • Fix Version/s is not mandatory in NEW and ANALYZED state
  • Fix Version is have to be set when it is moving to IMPLEMENTED sate
  • Fix Version/s is required (mandatory but can be changed) in IMPLEMENTED and RESOLVED state for Administrators
  • Fix Version/s is read-only in IMPLEMENTED and RESOLVED state for other users

Workflow:

NEW -> ANALYZED -> IMPLEMENTED -> RESOLVED

 

Code:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.roles.ProjectRoleManager;

//Read Only is False if user role is Administrator
def issue = underlyingIssue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager)
def role = projectRoleManager.getProjectRole("Administrators")
def userIsAdmin = projectRoleManager.isUserInProjectRole(currentUser, role, issue.getProjectObject())

//Fix Version/s field value
def fixVersions = getFieldById("fixVersions")


//Current status of the issue
def issueStatus = underlyingIssue.getStatus().name

//IMPLEMENTED, RESOLVED state restricts the modification of the  Fix Version/s if user role is not Administrator
if (!userIsAdmin){
  if (issueStatus == "Implemented" || issueStatus == "Resolved"){
    fixVersions.setReadOnly(true)
  } else {
    fixVersions.setRequired(true)
  }

}

 

3 answers

1 accepted

1 vote
Answer accepted
Thanos Batagiannis _Adaptavist_
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 10, 2019

Hi @Ferenc Ghido 

Was good to meet you in MetaInf conference. 

So as we said the inline editing thing is indeed a bug and will be released in the week - please follow  SRJIRA-3004 and SRJIRA-3462 in order to be up to date. 

Now regarding the behaviour. The script should be an Initialiser and should look something like 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.*

@BaseScript FieldBehaviours fieldBehaviours

// if underlying issue is null means that we are trying to create a new issue - so do nothing
if (!underlyingIssue) {
return
}

def fixVersionField = getFieldById(FIX_FOR_VERSIONS)
def currentStatusName = underlyingIssue.status.name

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

def projectRole = projectRoleManager.getProjectRole("Administrators")
def isAdminRole = projectRoleManager.isUserInProjectRole(currentUser, projectRole, underlyingIssue.projectObject)

// Fix Version/s is not mandatory in NEW and ANALYZED state
if (currentStatusName in ["New", "Analyzed"]) {
fixVersionField.setRequired(false)
}

// Fix Version is have to be set when it is moving to IMPLEMENTED sate
if (actionName == "Implemented") {
fixVersionField.setRequired(true)
}

// Fix Version/s is required (mandatory but can be changed) in IMPLEMENTED and RESOLVED state for Administrators
if (currentStatusName in ["Implemented", "Resolved"] && isAdminRole) {
fixVersionField.setRequired(true)
}

// Fix Version/s is read-only in IMPLEMENTED and RESOLVED state for other users
if (currentStatusName in ["Implemented", "Resolved"] && !isAdminRole) {
fixVersionField.setRequired(false)
fixVersionField.setReadOnly(true)
}

Please let me know if this does the trick.

Kind regards, 

Thanos

Ferenc Ghido June 17, 2019

Thank your for your support!

Best Regards,

Ferenc Ghido

0 votes
Hemant August 4, 2020

I am unable to get this to work as well. I have around 50 fields some of which are being made read only depending on the group a user belongs to. If he belongs to x group, he can edit otherwise he cannot. This functionality works perfectly fine in the edit screen but users are able to edit fields in view screen using inline edit. 

This is a functionality we really need to get to work and disabling inline edit for the whole JIRA seems to be the only option we are left with (which is horrible) . Are there any other ways i can disable inline edit just for a single issuetype/ workflow. @Thanos Batagiannis _Adaptavist_ 

I tried using the setAllowInlineEdit(false) in the behaviour initializer. Does not work. Works only for field behaviours and adding more than 100 field behaviours would make jira super slow

0 votes
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2019

Hi @Ferenc Ghido ,

I just tried it on my instance and the behaviour does not execute on view issue screen either. I would advise to take a look at this topic, maybe the JS will help, although I would agree that it is not ideal.

Antoine

Ferenc Ghido May 22, 2019

Hi @Antoine Berry ,

Thank your for your suggestion. I saw that there are also a Bug opened for similar issue (not the same but similar): https://productsupport.adaptavist.com/browse/SRJIRA-3004 

I still keep open my request if there are better solution.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events