How to restrict change custom fields from specific values? Scriptrunner

NewByatl June 10, 2021

Greetings!

I have a next case:

I m  trying to restrict changing customfield (type: Deviniti [Dynamic Forms] - Dynamic Select)

It has 3 values: error, customization, changeApp. I want to forbid changing values from error to changeApp and customization to changeApp. 

I suppose it can be done by scripts (listeners or behaviours) but i have no relevant expirience of writing dificult scripts. If someone can help or have workaround, pls help.

image-2021-06-10-13-35-16-512.png

1 answer

1 accepted

0 votes
Answer accepted
Max Lim _Adaptavist_
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.
June 12, 2021

Unfortunately, from Deviniti documentation, Dynamic Forms for Jira is not compatible with ScriptRunner's Behaviour, you can log your request to ScriptRunner support portal. The more requests, the likely the Product Manager will work on this matter.

Anyway, for other users, Behaviour is the best choice in this use case. If you are using ScriptRunner 6.26 or above, setFieldOptions() is made easier.

So, you can attach following snippet to Initialiser:

def selectField = getFieldByName("Your Select Field Name")

if (underlyingIssue && selectField.getValue()) {
if (selectField.getValue() == "error") {
selectField.setFieldOptions(["error", "customization"])
} else if (selectField.getValue() == "customization"){
selectField.setFieldOptions(["error", "customization"])
}
}

First if statement tests whether you are editing an existing issue with the field is set before. The rest should pretty much self-explanatory.

Max Lim _Adaptavist_
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.
June 12, 2021

ah, the snippet can be actually further simplified:

def selectField = getFieldByName("Your Select Field Name")

if (underlyingIssue && selectField.getValue()) {
if (selectField.getValue() != "changeApp") {
selectField.setFieldOptions(["error", "customization"])
}
}  
NewByatl June 13, 2021

I just tested it, awesome! Thank you so much!

Suggest an answer

Log in or Sign up to answer