Hi,
How can i automatically adds watchers based on a custom field in JIRA when a issue is created?
I have the ScriptRunner plugin.
Does anyone know how I can do this using scriptrunner?
If anyone knows, could you provide me a script?
@Fernanda de Souza Thaumaturgo
I recommend to use Automation for Jira Lite by adding automation rule
- when issue is created
- if JQL result passed (custom field value = {Data})
- Add watcher
I already have ScriptRunner plugin, do you know if i can use this one to do this automation?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Fernanda de Souza Thaumaturgo
Try this code as post-function after issue created
import com.atlassian.jira.component.ComponentAccessor //Get appropriate managers def watcherManager = ComponentAccessor.getWatcherManager() def cfManager = ComponentAccessor.getCustomFieldManager() //Get your custom field object def customField = cfManager.getCustomFieldObject().find{it.name == "Custom Field Name"} //Get the custom field value def userToWatch = issue.getCustomFieldValue(customField) //Set the user to watch the provided issue watcherManager.startWatching(userToWatch, issue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Mohamed Adel !
Unfortunately this code only works for the server version.
But thank you so much for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fernanda de Souza Thaumaturgo,
I can confirm that you will be unable to use Behaviours as responses have suggested within ScriptRunner for Jira Cloud as the cloud version of the plugin does not have the Behaviours feature like the server version does.
The reason we are unable to provide this functionality is due to the restricted functionality and API's which Atlassian provide inside JIRA Cloud, due to the fact that Atlassian only provides a Rest API in Jira Cloud and not the same Java API that the server version contains.
You can see more detailed information on the differences between ScriptRunner for JIRA Cloud and ScriptRunner for JIRA Server inside of the documentation page located here.
However, I can confirm that you can achieve this requirement inside of ScriptRunner for Jira Cloud by adding in a Run Script post function configured as the last post function, on the Create Transition of the workflow.
The script will need to get the custom field value off of the issue and if the custom field value matches the expected value then adds a user as a watcher on the issue.
I can confirm that we have lots of examples in the documentation page located here which show how to extract the values from different custom field types and that we have the example script located here which shows how you can add a user as a watcher.
You will be able to take these scripts and will be able to use these as a reference guide to help create the script that you require.
If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can't out of the box. You will need a plugin. I believe the Behaviors plugin will allow you to do it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I already have ScriptRunner plugin, do you know if i can use this one to do this automation?
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.