It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set particular custom field read only

Hi There,

I am currently administrating a JIRA project. and i have added several cutome fields. and now there is a require for restricting editing on certain fields during the lifecycle of an issue, or in another word, once some of the custom fields have been created, they should be disabled from editing for all users.

I am thinking there would be two way of doing these,

  • make the field read only, but seems the read-only text field is not design for this scenario, any other suggestions?
  • do some user permission setting, but seems there is no permission setting for view only.

Could you guys suggest a solution or workaround doing this?

Thanks in advance.

Liwei

8 answers

1 accepted

16 votes
Answer accepted

Hang on, there's a whole lot of totally unneccesary code being thrown around here.

Peter's original answer is correct, as is Henning's follow up.

Put the field on the CREATE and VIEW screens. Do not put it on the EDIT screen.

The user can then add data to the field when it is created. They will not be able to change it again. Click-to-edit is disabled for fields that are not on the edit screen. If you need to change it later in the process, you can put it on a transition screen.

But the fields still needs to be viewed during the flow, and with my understanding of JIRA, if the certain fields can be viewed, it also means the fields can be modified.

Like Flash Sheridan likes this

What do you mean with "during the flow"? If a field is editable on the view screen depends on if the field is on the edit screen.

If you add the field to a transition screen it's editable in this transition (independend from the view/edit editability). A transition could be "protected" by a condition.

Hi Liwei,

If the fields are only viewable on the view screen (the screen associated with the view issue action in your Screen Scheme) and not on any other screen (except the screen associated with the Create issue action in your screen scheme) they can not be edited.

Best regards,

Peter

The field will still be editable in batch edit.

Like Flash Sheridan likes this

I think the issue with this solution is that it means the fields are never editable. Is there a way to have an edit screen but make it no longer accessible after a certain point in a workflow?

Like Flash Sheridan likes this

No. 

You can use workflow properties to block all edits when in a status, but not field edits.  The way to handle what you're asking for is to move edit into the workflow, as mentioned above.

Thanks for answering. I'm sorry - I'm not clear on what you mean by 'move edit into the workflow'. did read over the 'above' a few times! I want everything to be editable at any time the ticket is viewed, right up until the issue is transitioned to 'archive' status - whereupon, I guess ideally I would like the 'Edit' option to simply disappear when viewing the ticket.

You can edit a field in two ways basically. 

If you have it on the "edit" screen, then it's editable when editing the issue or by clicking in the view screen, and in places that support edit functions.  If you remove it from there, it's effectively read-only (barring place 2)

If you put a field on a transition screen, then the user can change the content during a transition.  That's "move edit into the workflow".  Transitions are locked to status and can be controlled with conditions and validators.

If you want to remove "edit" for all fields of an issue because it's in a status, then the best option is to use workflow properties - set jira.editable = false on the "archive" status in your workflow.  (Have a look at the default uneditable JIRA workflow - it has the flag set on "closed")

Hi Nic - thanks - the last thing you said sounds perfect for what I want to do. Unfortunately I can't view the properties of that JIRA workflow's 'closed' status precisely because it's uneditable.I tried putting jira.editable in the property key and 'false' for property value but I get Key starts with 'jira.' but is not known to JIRA...

Ah, sorry, I usually take a copy of it, which you can then edit.

But it's also on https://confluence.atlassian.com/jira/workflow-properties-189949.html

Brilliant - it's jira.issue.editable - thanks a million!

Right: the field can still be changed during a Bulk Edit. Is there any way to prevent that? I used SR to make a field Read-only, but even that does not prevent a user who has the bulk update permission from making changes to this field!

Like Flash Sheridan likes this

No, Behaviours can't prevent bulk-edit.

Wow - that's disappointing. Guess we'll have to hand out that Bulk Edit permission more sparingly...

Thanks,

Jozef

Like Flash Sheridan likes this

The JIRA Field Security Plugin prevents bulk updates, but it brings lots of other issues. I'm ready to give up on it because its not worth the trouble.

The "new Jira issue view" does away with the distinction between the Edit and View screens, so unfortunately this answer is no longer relevant.

As far as I can see, there is no longer a way to make a custom field read only.

The answers remain valid for Server, and Cloud users on Classic projects.  Next-gen is very different, and is expected to re-implement issue security soon, at which point the answers will become right for it again.

Like Aamir Saleem Sani likes this

We're on Jira Cloud and our projects were created before Next-gen rolled out, thus I assume we are "Classic".

We have a few screens in use, but can't see whether they are Create, Edit or View.  Most screens I deal with have names like "default issue" or "workflow".  If I delete a field from these screens then I can no longer see it.  

I wonder if the implication here is configuring things differently than now, to allow read only custom fields.  Please advise of the steps I'll need to do.  I've read these posts, but can't seem to connect the dots.  

Hi Liwei,

If you only add those field on the issue create screen and don't add those fields to the edit screen in or any screens you use during your workflow they should not be editable after doing an issue creation.

Best regards,

Peter

Thanks Peter.

But if i create an isolated edit screen or view screen, the fields would be viewed during the workflow lifecycle.

I would really like the fields to be viewed and also non-editable.

Like # people like this

Hey Liwei,

I think that should be possible using Behavious plugin, as it allows you to make certain fields to be read-only.

You can download the plugin here:

https://marketplace.atlassian.com/plugins/com.onresolve.jira.plugin.Behaviours

Similar discussion was in the following Answers:

https://answers.atlassian.com/questions/113437/how-to-set-some-fields-as-read-only-after-submit-an-issue

I hope that helps.

Cheers,

Cheers~~Plugins, i love it. but i am not the system admin, and current there is no plan for inviting any plugins in our company JIRA support team

I'm sorry to hear that.

Let's wait and check if there are any users who can suggest some better workarounds which might work on your side.

Cheers. :)

“This app has been archived”

Behaviours became part of Scriptrunner several years ago.

Besides using a plugin the normal way to archive this is to remove the field from the edit screen and add a transition to the corresponding workflow with a transition screen which contains the field. Access to the transition can be controlled through workflow conditions.

Henning

Thanks Henning~~ i think the transition control is a good idea, but the default tranisiton conditions provided by JIRA is really limited. But i will try your advices.

Like Flash Sheridan likes this

Hi Team,
We have a requirement to make editable only 2 custom filed from edit screen out of 30 for a specific group only i.e project developer role can edit 2 fields only.Is it possible using  Behaviour (Adaptavist script runner) ?
Regards,
Sushanta

Hi Liwei,

You would need to develop your own custom field to achieve this functionality.

Thank you

Bhushan

Yes, i currently trying to use some scripts to work around make the 'click to edit' link to be hidden

Why not write your own custom field that is editable by selected project roles or groups?

Like Flash Sheridan likes this

you can hide/show field to specific group by using following scritp, chenage custom field id, group name as per your requirement

<script type="text/javascript">  
jQuery(document).ready(function($) {
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {	
		hideFieldForGroup();    
	});
		hideFieldForGroup();
function hideFieldForGroup(){
        var user=getCurrentUserName();		
		var statusText=$('#status-val').text();	
		var status=$.trim(statusText);
		if(isUserInGroup(user,'Developers') && status=='In Progress'){			
			$("#customfield_10571").closest('div.field-group').hide();
		}else if(isUserInGroup(user,'Users') && status=='Open') {
			AJS.$("#customfield_10571").closest('div.field-group').show();
		}

}
function getCurrentUserName()
{
var user;
     AJS.$.ajax({
        url: "/rest/gadget/1.0/currentUser",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
        }
     });
     return user;
}
  
  
function getGroups(user)
{
var groups;
     AJS.$.ajax({
        url: "/rest/api/2/user?username="+user+"&expand=groups",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            groups = data.groups.items;
        }
     });
     return groups;
}
function isUserInGroup(user, group){
    var groups = getGroups(user);
    for (i = 0; i < groups.length; i++){
         if (groups[i].name == group){
              return true;
         }
    }
    return false;
}
    
 });

</script>

oh, really? we can directly use the jQuery libray? is this default supportive by JIRA?

yes, jquery plugin will be included in jira, you can use AJS(Atlassian JavaScript) frame work also

check this

https://developer.atlassian.com/display/AUI/Getting+Started+with+AUI

Funny. Where are you going to put this script? At least you need to have access to Jira working directory (to modify vm templates). And merge your changes each time Jira upgrades. Not really a good way to my opinion.

Hi Rambanam,

 

Can we use the above script for hiding custom field according to user role permission. Actually my requirement is."Label field should be visible only to admin role users" on create screen.

 

Regards,

Tushar

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

864 views 6 24
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you