Custom field value validation

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2020

Hello Team,

I have two custom fields, the second field should pop up in create issue only if the value in first custom field matches certain text.

Is it possible to configure something like that ? Do suggest if anyone has done something like that.

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 30, 2020

Hi @Vishal ,

This is possible using an addon. I would advise ScriptRunner through its behaviours module. It is a very complete addon with great support. I can help with the code if needed.

Antoine

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2020

Hello Antoine,

That would be great help, I am trying it with behaviour only but couldn't get it done. If you can help with the code would be fantastic.

 

Vishal

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 30, 2020

Create a new behaviour and link it to the first field. Add a custom code : 

import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

int secondFieldId = 12800
def secondField = getFieldById("customfield_" + secondFieldId)
secondField.setHidden(true)

//if underlyingIssue does not exist, it means we are in the issue creation
if (!underlyingIssue){
int firstFieldId = 12900
def firstField = getFieldById("customfield_" + firstFieldId)
def firstFieldValue = firstField.getValue()

if (firstFieldValue.contains("123")){
secondField.setHidden(false)
}
}

You have to adapt it with your field ids and requirements. Let me know if you need something more specific. Note that this code will only trigger when the focus is lost on the first field.

Like Vishal likes this

Suggest an answer

Log in or Sign up to answer