• Community
  • Products
  • Jira Software
  • Questions
  • /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.behaviours.BehaviourManagerImpl] Script function failed on issue:

/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.behaviours.BehaviourManagerImpl] Script function failed on issue:

Kevin Dalton March 31, 2016

2016-03-31 10:08:41,492 http-bio-8080-exec-92409 ERROR aa017659 608x22150305x3 178cxf1 10.184.177.58,10.160.5.7 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: (create issue) project/issuetype: FACSUP/Privilege Requests, user: aa017659, fieldId: customfield_15620, file: <inline script> java.lang.NullPointerException: Cannot invoke method contains() on null object at java_lang_String$contains$6.call(Unknown Source) at Script1.run(Script1.groovy:6)



Behaviours code


 

def blockedCf = getFieldByName("Factory Tool")
def reasonCf = getFieldByName("Pipeline")
if (blockedCf.value.contains("Feature Tracker")) {
   reasonCf.setRequired(true)
} else {
   reasonCf.setRequired(false)
}

3 answers

0 votes
Kevin Dalton April 1, 2016

Issue was resolved with the following

 

// get a pointer to my checkbox field
def blockedCf = getFieldByName("Factory Tool")
  
// Get the blockedCf value as a string
String blockedCfValue = blockedCf.getValue()
  
// Get a pointer to my reason select list field
def reasonCf = getFieldByName("Pipeline")
  
// If the  Factory Feature Tracker option is checked make the pipeline field required
if (blockedCf?.value?.contains("Feature Tracker")) {
    reasonCf.setRequired(true)
} else {
    reasonCf.setRequired(false)
}
0 votes
Kristian Walker _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.
March 31, 2016

Hi Kevin,

I am assuming that the field you are checking the value of is a checkbox field and so have enclosed a sample script of how you make a field required based on the value of a select list based on your example above. This behaviour should be configured on the blockedCf field.

// get a pointer to my checkbox field
def blockedCf = getFieldByName("Factory Tool")

// Get the blockedCf value as a string
String blockedCfValue = blockedCf.getValue()

// Get a pointer to my reason select list field
def reasonCf = getFieldByName("Pipeline")

// If the  Factory Feature Tracker option is checked make the pipeline field required
if (blockedCfValue == "Feature Tracker") {
    reasonCf.setRequired(true)
} else {
    reasonCf.setRequired(false)
}

I hope this helps

Kristian

0 votes
Kevin Dalton March 31, 2016

Factory Tool is a checkbox field that is required

Kevin Dalton March 31, 2016

It appears to be throwning the errors when the user selects the option Feature Tracker which requires Pipeline by the script and the unselects Feature Tracker when makes Pipeline unrequired.

Kristian Walker _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.
March 31, 2016

Hi Kevin,

I have updated my example script above so that it now shows how to make a field required when a check-box is set to certain value.

This script was developed using JIRA 7.1.0 and ScriptRunner version 4.2.06.

I hope this helps.

Thanks

Kristian

 

Kevin Dalton April 1, 2016

Behaviors plugin still throws the an error when unselecting the field that is makes the other field required

Kristian Walker _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.
April 1, 2016

Can you please confirm what version of ScriptRunner  and JIRA you are using as well attach a screenshot of how you can configured my code above.

I have tested this on my instance and get no error thrown on my system. Also can you confirm if any of the fields referenced in this behaviour are used by any other behaviours or scripts as these could be the cause.

Also could you please post a screenshot of the error being displayed.

Once we have this information then we will be able to look to help you further.

Thanks

Kristian

 

Kevin Dalton April 1, 2016

JIRA 6.3.12

SR 3.0.16

Kristian Walker _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.
April 1, 2016

Can you please provide all of the other details requested as well as at the moment we are unable to replicate your issue.

Thanks

Kristian

Kevin Dalton April 1, 2016

behaviour config.JPG

Kristian Walker _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.
April 1, 2016

Could you please try using my modified code above which I have incuded below as this is the correct syntax for checking check-box values inside of Behaviours.

// get a pointer to my checkbox field
def blockedCf = getFieldByName("Factory Tool")
 
// Get the blockedCf value as a string
String blockedCfValue = blockedCf.getValue()
 
// Get a pointer to my reason select list field
def reasonCf = getFieldByName("Pipeline")
 
// If the  Factory Feature Tracker option is checked make the pipeline field required
if (blockedCfValue == "Feature Tracker") {
    reasonCf.setRequired(true)
} else {
    reasonCf.setRequired(false)
}

If using this code you still get the error can you please post a screenshot of where the error is displayed along with an extract of the atlassian-jira.log file from when the behaviour is executed.

Thanks

Kristian

Kristian Walker _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.
April 1, 2016

I have tested the code above using JIRA 6.3.5 and ScriptRunner 3.0.16 and confirm that it works as expected. If further assistance is needed please provide screenshots of the error as well as an extract of the atlassian-jira.log file.

Thanks

Kristian

Kevin Dalton April 1, 2016

It works but the only issue I see is that is there are 2 checkboxes selected for Factory Tool the Pipeline field i not required.

Kristian Walker _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.
April 1, 2016

Hi Kevin,

Yes with Checkboxes you can select more than one and the Pipeline field will only be made required when just the feature tracker option is selected.

You will either need to change the field to be a Single Select List if you wish to only make the pipeline field required when Factory Tool is selected or you will need to add extra if statements for each combination of options that could contain the Feature Tracker option checked.

I hope this helps.

Kristian

Suggest an answer

Log in or Sign up to answer