Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to make the due date field read only after it is set using Scriptrunner behavior

Beth Starr August 5, 2019

I need a script that will check and see if the due date is != null and if it has a value, then make the due date read only, else the due date should be writeable.  I am not able to get this to work. 

I have been trying to get this to work with behaviors but have been unsuccessful.  I would prefer to have a script and not pick the workflow and steps because not all the projects this is to be used for share the same workflow and I don't want to have multiple behaviors for each of the workflows.

I am new to scripting and when trying to use the below it is making the field read only all the time.


import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp

def dueDate = getFieldByName("Due Date")

if (dueDate != "") {
dueDate.setReadOnly(true)

}
else {
dueDate.setReadOnly(false)
}

1 answer

0 votes
Mike Rathwell
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.
August 5, 2019

Hi @Beth Starr 

I had a quick look and my first inclination was the right one it seems... The answer is simpler and just leave "Due Date" off the edit screen as seen here. The answer @MoroSystems Support noted there was seconded by @Nic Brough who I've long respected in the "been there, done that, broke that" realm with Jira.

That is also my vote to simplify the solution without having something that needs to be maintained (not least of which your import com.atlassian.jira.component.ComponentAccessor which moves in the API when going to Jira 8)

Beth.Starr
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 5, 2019

I thought that would work too but since there are many projects that use the same configuration I can't remove it without impacting those projects.  I need it to set the field as read only for just a few projects. 

Suggest an answer

Log in or Sign up to answer