script field update only jiraadmin

Hi,

we are having a custom field , based on that we are sending mail & updating the customfield via script runner , but sometimes if user manually update the customfield our scriptrunner not able to send email ,is there any option available in scriptedfield to  check that scripted customfield can be updated only by Jiraadmins ?.

Customfield update is not done based on transition , scriptrunner script executes as Jiraadmin user .

 

2 answers

1 accepted

Hi vijay,

So you ask if there is a way to add a "condition" in the scripted field to check if the user who updates the issue, (and the updated field is 'connected' with scripted field) is an admin user. Unfortunately you cannot do that in your - responsible for the scripted field - script. Also the scripted fields cannot be updated directly but only via the fields that are 'connected' to it.

Therefore your question and please correct me if I am wrong, is how to allow only admins to edit specific fields in an issue and again this is not possible.
A workaround I can think is to associate a behaviour to the "suspicious" fields and make them read only if the user is not an administrator, for example

import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def field = getFieldByName("a field name")
field.setReadOnly(true)
if (groupManager.isUserInGroup(currentUser, "jira-administrators")) {
    field.setReadOnly(false)
}

Hope that helps, somehow...
Regards

 

Hi Vijay,

I have enclosed below a sample Behaviour script which can be applied to the field read only. The script will check to see if the current user is in a group such as the jira-administrators group and if the user is in the administrators group then it will make the field writeable else it will be read only for all other users.

Below I have attached the code and config needed.

This code was developed and tested on JIRA 6.4.12 using ScriptRunner 4.1.3.10.

Code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
  
// Get pointers to the custom field(s) required
def cf = getFieldByName("Demo Text Field")
  
// Get the current logged in user
def user = ComponentAccessor.getJiraAuthenticationContext().getUser().name
  
// Get a pointer to the admin group
UserUtil userUtil = ComponentAccessor.getUserUtil()
def group =  userUtil.getGroupObject("jira-administrators")
  
// By default make the field read only
    cf.setReadOnly(true)
  
if(userUtil.getGroupsForUser(user).contains(group)){
 // If the user is in the restricted groups field then show the field(s)
    cf.setReadOnly(false)
}

 

Config:

image2016-4-8 11:20:51.png

I hope this helps.

Kristian



Thanks @Kristian Walker (Adaptavist)

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...

492 views 6 11
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