Hi Community !
Use case : In Multiple select list, we need to block the creation of issue if the user selected more of 3 values.
We have Scriptrunner, so I think I can to do with a validator at the create like :
Num = getCustomFieldValue (Myselectlist).size()
If (Num>3) {invalidexception ...etc.... }
But size() seems to be not OK.
Do you have another idea to do that ? with Behaiviour may be ?
thanks in advance,
I see no reason why this would not work as a validator.
You may want to protect against zero values being selected. In this case, getCustomFieldValue will be null and size() then definitely won't work.
But have you tried a simple scripted validator implementation so you can leverage the cfValues map
Notice the ? before size(). This will make sure that size won't fail even if the cf value is null.
If you really prefer the full custom validator, then something like this perhaps:
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def myMultiSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("my custom field")
def numValues = issue.getCustomFieldValue(myMultiSelect).value?.size() ?: 0
if(numValues >3 ){
throw new InvalidInputException(myMultiSelect.hiddenFieldId, "You may not select more than 3 values")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @PD Sheehan
The above condition shows error. As well as the script. The error: No matching method found. Could you help with this.
I want to achieve the same on create and edit screen. Can the same be achieved by Behavior?
Many Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It will be easier to diagnose your error if you share your full script and the exact location of the error.
And yes, it is possible to achieve the same requirement with behaviour. However, workflow validators are more robust because they will also work in the case of API-triggered transitions.
Behaviours provides more immediate feedback to the user and can validate during edits.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @PD Sheehan
Thank you for your response.
I'm getting the same error which is mentioned by @Dustin Glienke .
As for the script which you mentioned in your initial response above
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def myMultiSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("my custom field")
def numValues = issue.getCustomFieldValue(myMultiSelect).value?.size() ?: 0
if(numValues >3 ){
throw new InvalidInputException(myMultiSelect.hiddenFieldId, "You may not select more than 3 values")
}
I'm getting the error at def numvalues = def numValues = issue.getCustomFieldValue(myMultiSelect).value?.size() ?: 0
Error is :: no such method found.
Thanks..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is the code running? Not all errors in a script editor will prevent the execution.
Sometimes, those errors are there only because the editor can't determine the type of a value.
You can try something like this to force the error away:
import com.atlassian.jira.issue.customfields.option.Option
import com.opensymphony.workflow.InvalidInputException
def selectedOptions = issue.getCustomFieldValue("my custom field") as List<Option> ?: []
def numValues = selectedOptions.size()
if(numValues >3 ){
throw new InvalidInputException(myMultiSelect.hiddenFieldId, "You may not select more than 3 values")
}
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.