Hi,
I'm trying to create a behaviour that checks the content of Description. If the field contains the string "We can't log you in right now" it should set an error but I can't get it working. Any idea how can i go about this?
Hi @Joel Batac
Could you provide some more information, i.e. when do you want this behaviour to trigger? Is it on the Create, Edit or some other screen?
I am looking forward to your clarification.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Joel Batac
For your requirement, you must create a Server-Side Behaviour configuration for the Description field.
Below is a sample working Behaviour code:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def description = getFieldById(fieldChanged)
def descriptionValue = description.value.toString()
description.clearError()
def wordArray = ['We', "can't", 'log', 'you', 'in', 'right', 'now'] as String[]
if (descriptionValue && containsWords(descriptionValue, wordArray)) {
description.setError('Error')
}
static boolean containsWords(String input, String[] words) {
def lastInput = input.split(' ').last()
if (lastInput.startsWith('n') && lastInput.endsWith('w') && input.split(' ') == words ) {
Arrays.stream(words).allMatch(input::contains)
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Server-Side Behaviour configuration.
Below are a couple of test screenshots for your reference:-
1. If the Description field contains all the text the error message is displayed as shown in the screenshot below:-
2. If the Description field doesn't contain all the text specified, the error message will not be displayed as shown in the screenshot below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Joel Batac
Has your question been answered?
If yes, please accept the answer provided.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_ - I tried the solution but not working for me. It's not setting the Error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Joel Batac
Could you please share the text that you have tested with?
Also, please the me know the current version of Jira and ScriptRunner you are using.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Joel Batac
As requested in my previous comment, could you please share the text you have tested with?
Also, please the me know the current version of Jira and ScriptRunner you are using.
Thank you and Kind regards,
Ram
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 @Joel Batac
As requested in my previous comment:-
As requested in my previous comment, could you please share the text you have tested with?
Please share the sample text that you have tested with so I can test it here in my environment.
Thank you and Kind regards,
Ram
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.