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.FieldBehavioursdef fieldName = 'xxx' // Replace with your actual field namedef errorMessage = 'Error message' // Your error message// Get the field by namedef field = getFieldByName(fieldName)// Check if the field is not nullif (field) {// Set the error message on the fieldfield.setError(errorMessage)} else {// Optionally handle the case where the field is not foundlog.warn("Field '${fieldName}' not found.")}
Else. Share you script and maybe I can help.
Howard
Hi @Howard Nedd the answer you provide is for jira data center, how to use setError in jira cloud? thank you
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?
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">'
It looks like you're new here. Sign in or register to get started.