You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
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
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:
Otherwise:
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.