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

7 answers

1 accepted

14 votes
Accepted answer

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.

Henning Tietgens Community Champion Nov 05, 2013

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.

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?

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!

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

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.

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.

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

1 vote
Henning Tietgens Community Champion Oct 27, 2013

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.

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?

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 Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,304 views 12 19
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