It's not the same without you
Join the community to find out what other Atlassian users are discussing, debating and creating.
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) }
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.
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
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
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
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
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
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
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) }
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.
Read moreAtlas Camp is our developer event which will take place in Barcelona, Spain from the 6th -7th of September . This is a great opportunity to meet other developers and get n...
Connect with like-minded Atlassian users at free events near you!
Find a groupConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.
Start an AUGYou're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.