Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Custom error message in Scriptrunner Behaviours?

Hello guys,

looking for solution to throw custom error message into the portal request screen via behaviours instead of generic one. 

My behaviour is like:

def projectComponentManager = ComponentAccessor.getComponent(ProjectComponentManager)
def projectManager = ComponentAccessor.getComponent(ProjectManager)

def mandatory = false
def component = getFieldById("components").getValue() as List

if (component?.any{it.name == "ABC"}) {mandatory = true}
if (component?.any{it.name == "XYZ"}) {mandatory = true}

if (mandatory == true)
{
getFieldById("attachment").setRequired(true)
getFieldById('customfield_10201').setRequired(true)
}
else
{
getFieldById("attachment").setRequired(false)
getFieldById('customfield_10201').setRequired(false)
}

And yes, I know that attachments dont work in here, but I need to remove the optional word as well and I am checking for attachment in validator.

Need to throw custom message for CF_10201.

Tried .seterror but without success.

Lastest Scriptrunner at JSD 4.13.2

Thanks, Tom

1 answer

Hi Tom,

 

I am not sure which ScriptRunner version that you have tested with. I tested below script with Latest ScriptRunner (6.19) and the error appear correctly if I used setError() method.

import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.bc.project.component.ProjectComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.ProjectComponent


def projectComponentManager = ComponentAccessor.getComponent(ProjectComponentManager)
def projectManager = ComponentAccessor.getComponent(ProjectManager)

def mandatory = false
List <ProjectComponent> component = getFieldById("components").getValue() as List

if (component?.any{it.name == "ABC"}) {mandatory = true}
if (component?.any{it.name == "XYZ"}) {mandatory = true}

if (mandatory == true)
{
getFieldById("attachment").setRequired(true)
getFieldByName("TextField").setRequired(true)
getFieldByName("TextField").setError("TextField is required")
}
else
{
getFieldById("attachment").setRequired(false)
getFieldByName("TextField").setRequired(false)
getFieldByName("TextField").clearError()
}

When ABC Component fill in:

Get IT help - IT Service Management - Service project 2021-02-14 01-48-38.png 

Otherwise:

Get IT help - IT Service Management - Service project 2021-02-14 01-49-39.png

Is this the same requirement that you wanted to achieve?

 

Regards
Amirul

Hi Amirul! You are kind of right, but this will show the error immediately - not after hitting create button. Is there a way how to achieve that?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
4.13.2
TAGS
Community showcase
Published in Jira Service Management

Why upgrade to Jira Service Management Premium?

We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan.  &nb...

133 views 0 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you