JIRA SM Behaviour to check Description field

Joel Batac February 28, 2024

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?

Here's the sample code.
def descriptionField = getFieldById("description")
def descriptionValue = descriptionField.getValue().toString()


if (descriptionValue.contains("We can't log you in right now"))
{
descriptionField.setError('Error')
}

1 answer

0 votes
Ram Kumar Aravindakshan _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.
February 29, 2024

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

Joel Batac February 29, 2024

Hi, during creation in the Service desk form. 

Ram Kumar Aravindakshan _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 5, 2024

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.

behaviour_config.png

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:-

test1.png

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:-

test2.png

 

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

Ram Kumar Aravindakshan _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 6, 2024

Hi @Joel Batac

Has your question been answered?

If yes, please accept the answer provided.

Thank you and Kind regards,

Ram

Joel Batac March 8, 2024

@Ram Kumar Aravindakshan _Adaptavist_ - I tried the solution but not working for me. It's not setting the Error

Ram Kumar Aravindakshan _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 8, 2024

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

Ram Kumar Aravindakshan _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 11, 2024

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

Joel Batac March 19, 2024

 

@Ram Kumar Aravindakshan _Adaptavist_ 

Jira Service Management 5.4.10

Scriptrunner Version: 8.8.0

Ram Kumar Aravindakshan _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 20, 2024

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

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events