how to make field read-only except certain project role and certain step at the same time?

For example, I have project roles: Developers, Users.
I want to make my field read-only except on step "In Progress" for Developers, and except on step "Open" for Users.
As a result: ("In Progress" AND Developers) OR ("Open" AND Users).
Help, please :)

7 answers

This widget could not be displayed.

you can do it by using javascript? let me know if you want do it using JS so i can help you!!

This widget could not be displayed.

I'm not sure that it will work excellent. But I'm ready to try.
How can I get projectrole and step using javascript?..

This widget could not be displayed.

small clarification!

do you want field read only on transition screen or view screen?

This widget could not be displayed.
only on Edit Screen..
This widget could not be displayed.

the following script will run on edit screen

<script type="text/javascript">  
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
		makeReadonly();
	});
		makeReadonly();
function makeReadonly(){
		var editFunction=$('#edit-issue-submit').val();
	if(editFunction === 'Update'){
        var user=getCurrentUserName();		
		var statusText=$('#status-val').text();	
		var status=$.trim(statusText);
		var devlopersRoleID='10010';//changr the project role id here
		var usersRoleID='10011';//changr the project role id here
		$("#customfield_10571").attr("readonly", '');
		$("#customfield_10572").attr("readonly", '');	
		if(isUserInGroup(user,devlopersRoleID) && status=='In Progress'){
			//to make text field read only
			$("#customfield_10571").attr("readonly", true);	
		}else if(isUserInGroup(user,usersRoleID) && status=='Open'){
			//to make text field read only
			$("#customfield_10572").attr("readonly", true);	
		}
		
	}

}
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 getUsers(roleID)
{
var users;
     AJS.$.ajax({
        url: "/rest/api/2/project/TEST/role/"+roleID,//change project Key here(need to replace TEST with your project key)
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            users = data.actors.name;
        }
     });
     return users;
}
function isUserInGroup(user, roleID){
    var users = getUsers(roleID);
    for (i = 0; i < users.length; i++){
         if (users[i].name == user){
              return true;
         }
    }
    return false;
}
    
 
});
</script>

wow, it looks nice! :)

And how can I get system fields? Duedate, assignee..

try with following code

//for dute field
$("#duedate").attr("readonly", true); 
//to hide date picker icon
$("#duedate-trigger").hide(); 
/to show date picker icon
$("#duedate-trigger").show(); 

try with this for assignee field
$("#assignee-field").attr("readonly", true);

I guess function isUserInGroup(user, roleID) doesn't work.

Without this function all is ok..

check the REST API in isUserInGroup(user, roleID) function

This widget could not be displayed.

Jira on demand?

This widget could not be displayed.
Joe Pitt Community Champion Nov 03, 2013

the behavior plug-in may offer that, but I don't know if you can have it installed.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

124 views 2 0
Join discussion

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