How I could rewrite this setError function about scriptrunner behaviour in jira cloud?
Hi Leo,
Unfortunately, in Jira Cloud the Behaviours module does not provide setError() function so this means your use case cannot be achieved.
The reason for this is that Behaviours in Jira Cloud uses the UI Modifications API from Atlassian, which does not provide a setError() method.
You can see what methods the cloud version provides here for reference. The closest workaround would be to use setDescription() method to add some text to indicate an error.
I hope this helps.
Regards,
Kristian
Hi @Leo Xie ,
In Jira Cloud, the ScriptRunner behavior API has some differences compared to the server version, particularly in how you handle field errors.
You can use the setError method on the field object directly, but the way you access fields and set errors can vary based on the context of your script.
I have done something similar the past:
import com.onresolve.scriptrunner.canned.jira.behaviours.FieldBehaviours
def fieldName = 'xxx' // Replace with your actual field name
def errorMessage = 'Error message' // Your error message
// Get the field by name
def field = getFieldByName(fieldName)
// Check if the field is not null
if (field) {
// Set the error message on the field
field.setError(errorMessage)
} else {
// Optionally handle the case where the field is not found
log.warn("Field '${fieldName}' not found.")
}
Else. Share you script and maybe I can help.
Regards,
Howard
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Howard Nedd the answer you provide is for jira data center, how to use setError in jira cloud? thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Leo Xie ,
You're correct that the ScriptRunner behavior API for Jira Cloud has specific nuances compared to the Data Center version. In Jira Cloud, the way to set errors on fields is slightly different, and the API is more limited.
In Cloud, you would use the setError method directly on the field object, but the context and how you access fields can differ.
Does that help?
Regards,
Howard
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Howard Nedd , I have tried to create behavior in jira cloud, but it remind this warning syntax message
Property 'setError' does not exist on type 'Field<"com.atlassian.jira.plugin.system.customfieldtypes:select">'
Property 'clearError' does not exist on type 'Field<"com.atlassian.jira.plugin.system.customfieldtypes:select">'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.