Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner behaviour based on Xray custom field

Venkat_S July 21, 2021

Hi,

I need suggestions for a ScriptRunner behaviour for the below condition which is based on the value of Xray "Test Repository Path"

 

WHEN the "Test Repository Path" is "NTG7 Widgets"

THEN the custom fields "Review" and "Review Comments" should be made mandatory.

ntgsui_scriptrunner.png

 

Any help here is highly appreciated.

 

Thanks in advance,

Venkat

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes

Hi there!

This is currently not possible via Behaviours, however, you can do this via a Simple Scripted Validator.

You can alter the following code to your requirements and add it to your validator.

def testRepo = cfValues["Test Repository Path"]
def textbox = cfValues["textbox"]

def result = false as Boolean

if(testRepo == "test 1") {
  if(textbox == null) {
      result = false
  } else {
      result = true
  }
} else {
    result = true
}

result 
0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 21, 2021

I don't have Xray so I can test and figure this out myself, but maybe I can give you some strategies for figuring it out yourself.

The critical thing you need to find out is if behaviour is even able to detect changes to Xray custom fields and getting the data.

So, create a behaviour configuration with the correct mapping and add your Xray field.

Then add a server-side script on that Xray field.

Add a short script to pull out the data from the custom field and display it on your form:

def xrayFld = getFieldById(fieldChanged)
def value = xrayFld.value
def rawValue = xrayFld.value
def formValue = xrayFld.formValue

def helpText = """value=$value (${value.getClass()})<br>
rawValue=$rawValue(${rawValue.getClass()})<br>
formValue =$formValue (${formValue .getClass()})<br>
"""
xrayFld.setHelpText(helpText)

If xray fields are supported by behaviour, you should see some red text below the field that will update each time you change the value in field.

If any of these values contain anything that looks like "NTG7 Widgets", then you should be able to detect that value and conditionally make the other 2 fields required or not.

For example, if the result of 'value' looks like "NTG7 Widgets (String)" then you could try a script like this:

def xrayFld = getFieldById(fieldChanged)

def requiredFieldNames = ['Review', 'Review Comments']

def required = (xrarFld.value == 'NTG Witdget)

requiredFieldNames.each{fieldName->
getFieldByName(fieldName).setRequired(required)
}
TAGS
AUG Leaders

Atlassian Community Events