Unable to clear error message after entering wrong value in behaviour custom field

anshu02
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.
November 6, 2019

We have a custom field where we want to get inputs between 1-10 only, and inputs apart from this range should give error message. So when we put incorrect value it gives the error message but after clearing the incorrect value and trying to keep the field blank it still throws error message. 

 

This is the script which we are using:

def abvField = getFieldById("customfield_12404")
def abvValue = getFieldById("customfield_12404").getValue() as Integer //Actual Business Value

if (abvValue > 10 || abvValue <1 )
{
abvField.setError("This field should contain a number value between 1-10")
}
else { abvField.clearError()}

1 answer

1 accepted

1 vote
Answer accepted
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 6, 2019

Hi @anshu02

Seems like this is a known issue with behaviour it does not work on when field clears it keep on holds the previous value

The workaround I can suggest you to consider script validator in workflow or custom listener

you can place validator script something like below

def value = cfValues['Filed Name for validation'] as Integer
if(value){
if(value < 11 && value > 0){
return true
}
else{
return false
}
}
else{
return true

BR,

Leo

Hemant August 28, 2020

Is there still no fix for this yet? @Leo 

Really need to make use of the behavior plugin instead of the validator and this bug is causing huge trouble. 

Would really appreciate any help

Alain Fragman September 6, 2022

I have encountered the same issue on my end as well. Can someone comment on a possible workaround?

Robert Leachman October 6, 2023

Also seemingly stuck on this in 2023. Any suggestions please?

Robert Leachman October 6, 2023

Looks like `clearError()` does the trick, this is working:

 

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.*

def assignee = getFieldById(ASSIGNEE)
assignee.setRequired(true) // marks with red star. Unassigned still a valid value so:

def newAssignee = assignee.getValue() as String

// clear any previous error and then be sure the ticket gets assigned
assignee.clearError()
if (!newAssignee || newAssignee == "-1") {
assignee.setError("Assignee is required")
}

Suggest an answer

Log in or Sign up to answer