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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.