Change custom field to read only by script runner

Yüksel Memiş October 18, 2017

When assignee changes I change the value of a custom field by using Adaptavist scriptrunner (I parse the company part from user email). But I need the field not to be edited by the user (only the script should update the field content).

Is it possible to make something like below:

1- make field read-only false

2- update field value

3- make field read-only true

I searched com.atlassian.jira.issue package but no such method like setReadOnly(boolean)

2 answers

1 accepted

0 votes
Answer accepted
Yüksel Memiş October 18, 2017

I solved the issue by setting a behaviour to make the field read only.

The field appears in both view and edit screens but thats not problem because it is read only.

Thank you both for your answers.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 18, 2017

Not sure why you think this is the right answer, when all you needed to do was what MoroSystems said.

2 votes
MoroSystems Support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 18, 2017

Hello!

 

There is a simple way to do it - put the field on View screen of the issue and don't put the field on Edit screen of the issue. Users will see the field, but will not be able to change it manually.

 

Simply because fields, which are not present on Edit screen have the ability to click-and-edit disabled for them and they are not present on any screen, which can edit them.

 

Scriptrunner should be able to edit them anyway.

Yüksel Memiş October 18, 2017

Hi,

The field is not visible when it is present only on the view screen. I can see it when I add it to the edit screen also.

More info:

I'am listening the issueAssigned event. Then editing the custom field value. The script always says that the run was successful.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 18, 2017

Your field must have data in it before it will appear on view, so you won't see it until the script has run.

You'll need to take another look at the script - I don't know how you are judging "run is successful", but to me that just means you know the script has run, not that has actually done what you want it to.

MoroSystems Support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 18, 2017

The script should not have any impact on the basic behaviour of JIRA.

I have just tested this on newest JIRA and it works just the way I told you and I was even able to modify custom field's text trough ScriptRunner without being able to edit it myself trough JIRA itself.

 

Could you please try to reproduce these steps:

1. Add new custom field to JIRA (make it e.g. test_custom_field and make it single line text field).

2. Put it on the View issue screen and Create issue screen, which differ from Edit issue screen for that particular issue and project

3. Create new issue and on creation issue screen, the field should be presented. Type any value in it.

4. After creation is completed, take a look on the issue, you newly custom created field should be here Note that you must have a value in the field to make it appear on View screen. The field is non editable and when you press "Edit" button, it is not presented on this screen.

For me, it works perfectly this way, even if I don't add it to Issue Creation screen.

 

If you are not sure about other things impacting behaviour of screens, you can try it on newly created test project.

Like Miguel Bravo likes this
Yüksel Memiş October 18, 2017

Hi Nic,

Ok. I understand the second part of your answer.

The problem is with the first part. No matter how many times I change the assignee (the script runs that many times), I cannot see the custom field on view screen. When I add it to the edit screen also then it becomes visible (with data in it).

To test this behavior I followed the below steps:

1- Wrote the script under script listeners (custom)

2- Added the custom field (text) to the view screen only

3- Created an issue in the related project

4- Changed the assignee many times

5- "Nothing happened. The field is not visible on view screen"

6- Added the custom field to the edit screen also

7- I expected to see the field because I thought that the field value was filled before (by the previous runs of the script). But the field was not visible.

8- Changed the assignee

9- The field became visible on the view screen

Suggest an answer

Log in or Sign up to answer