Powerscript for Jira – how to block editing a field or fields for a given role or roles.

Power Scripts™ – Jira script automation
JIRA PowerScript Sctipts Plugin is a very useful plugin if you want to automate tasks while working with Jira projects to save time on repetitive tasks. The most important features are the ability to automate repetitive tasks, scripts added to the workflow, transit, and event listener.

It can be found on atlassian marketplace under this link. Unfortunately, it is not free, but the price is very affordable.

Script code


I will not write how to create a new script file, because the documentation is written in a very easy language, just to block users from editing the fields, you need to attach our script under “live field” to make it work whenever someone opens a jira page. How to do it? It’s very simply:

The script code itself is trivially simple:

/*
This script will disable Field1, Field2, Field3 and Field4 from users who are not in the correct role.
*/

if(isUserInRole(currentUser(), "Project_Name", "Project_Role") == false) {
lfDisable("Field1");
lfDisable('Field2');
lfDisable('Field3');
lfDisable('Field4');
}

It is worth remembering that in PowerScript you can use the field name or its ID, so our script may look like this:

/*
This script will disable Field1 (customfield_10000), Field2 (customfield_10001), Priority and Original Estimation from users who are not in the correct role (Project Manager) for Lisiatko project.
*/

if(isUserInRole(currentUser(), "Lisiatko", "Project Manager") == false) {
lfDisable("customfield_10000");
lfDisable("Field2 ");
lfDisable("priority");
lfDisable("originalEstimate");
}

Why do I prefer to use field names instead of ID in case of custom field? Because it is much easier to read, when after some time we want to modify something in our script.

How it looks like in practice
Let’s assume that I want to block the possibility of editing three fields (Priority, Original Estimate, Labels) for all those who don’t have the role of “Project Manager” in the “Lisiatko” project. Then my code will look like this:

if(isUserInRole(currentUser(), "Lisiatko", "Project Manager") == false) {
lfDisable("priority");
lfDisable("originalEstimate");
lfDisable("labels");
}

And the effect will be that way:

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.