Hi Alex.
You shuold be using the behaviours module of SR. In that module, you will see that you don't need to use the customFieldManager.
Setup a behaviour for the project that you want this to affect, as we show you in the tutorial in the link above. When you edit your serverside Script, you will see that you can simply call, for example:
getFieldByName("Field").getValue()
If I were to adapt your script to a beaviour serverside script, I would do something like this:
def descField = getFieldById("description")
// You can also user getFieldById
// if you find the id of your custom field
def field = getFieldByName("Field")
def value = field.getValue()
if ( value ) {
descField.setReadOnly(true)
}
else {
descField.setReadOnly(false)
}
I would strongly advice that you take some time in running and understanding the examples that Katy has provided you in the documentation, since going through these will help you understand how to craft these scripts faster.
Please do tell me if you need anymore help.
DYelamos
This doesn't appear to be working. It looks like it can't ready the value of the custom field correctly.
To test this out I've done the following:
def desc = getFieldById("description")
def field = getFieldByName("Field Name").getValue() as String
desc.setHelpText("Custom field should be:" + field)
The rest of the logic seems to be working - ie. as long as I'm not writing code that's dependent on that field, it's fine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, the issue seems to be in the getValue() call.
def field = getFieldByName("FieldName")
def value = field.getValue()
def descField = getFieldById("description")
descField.setHelpText("Field Details: " + field + ", Field Value: " + value)
Then, I get this in the helptext:
Field Details: Form field ID: customfield_11250, value: null, Field Value: null
That's the correct custom field ID, but the field does have contents - I can see it on the form.
So, without it being about to pull the value, then I can't write logic against it.
Per your examples here: https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/scripted-conditions.html
I can access custom field contents with the JIRA API methods, but I can't use your methods (eg. setHelpText) on a field object returned from a JIRA standard call.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The field-dependency is just a person field (but not related to the current user) so can't use that article.
I did try a scripted condition, but am running into this (I think): https://productsupport.adaptavist.com/browse/SRJIRA-643
Can you confirm that bug is a real thing, the ETA for fixing it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex,
Can you post the script you are using and your versions of JIRA/ScriptRunner?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ScriptRunner: 5.0.4
JIRA: 7.3.8
JSD: 3.5.2
Script:
import com.atlassian.jira.component.ComponentAccessor
def descField = getFieldByName("Description")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def field = customFieldManager.getCustomFieldObjectByName("Field")
def value = getCustomFieldValue(field) as String
if ( value ) {
descField.setReadOnly(true)
}
else {
descField.setReadOnly(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex,
We have a couple different ways of doing this, depending on what you want the read-only field dependent on.
This article explains how use Behaviours to make a field read-only based dependent on user role or group.
You could also use a Scripted Condition to do this.
Let us know if those help you to achieve your desired result.
Kind regards,
Katy
Adaptavist Product Support
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I provided my script in answer to you.
Can you provide a working example?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.