Hi,
I've created a custom Listener on ScriptRunner that will be triggered everytime a customField is created, it will give the name and ID of the newly created CustomField.
So far I've managed to make it work. For that I have added one event on the Listener:
-- CustomFieldCreatedEvent
This is the code I'm using:
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.event.issue.field.CustomFieldCreatedEvent
def log = Logger.getLogger("New Customfield created:")
log.setLevel(Level.DEBUG)
def cfName = event.customField.getUntranslatedName()
def cfId = event.customField.getId()
log.debug "\nName: ${cfName}\n ID: ${cfId}"
Now what I want to do is to get the User that triggered this event, I tryied adding a new event which is EvenUser, that I believe should give me the user who triggered this event.
The problem is when the listener is triggered the "event" object will be assigned to CustomFieldCreatedEvent therefore I'm not able to call UserEvent functions.
I have read Scriptrunner documentation on multiple event:
https://scriptrunner.adaptavist.com/4.2.0.2/jira/listeners.html#_custom_listeners
I tryied below code for testing:
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.event.user.UserEvent
import com.atlassian.jira.event.issue.field.CustomFieldCreatedEvent
def log = Logger.getLogger("New Customfield created:")
log.setLevel(Level.DEBUG)
if(event instanceof UserEvent)
{
log.debug event.getUser()
}
else if(event instanceof CustomFieldCreatedEvent)
{
log.debug "\nName: ${event.customField.getUntranslatedName()}\nID: ${event.customField.getId()}"
}
But the only event it's catching is CustomFieldCreatedEvent and the debug output it's only the customfield ID not the user.
Could you please let me know if there is a way to accomplish this or what am I doing wrong? I've just started using ScriptRunner so there is many thing I'm still getting.