Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unable to fire on login event and dashboard view event in listener


I need to update my custom field value whenever I view a particular dashboard or whenever I log in to Jira. The code I've developed for this requirement is auto-updating the custom field if I chose issue created or issue updated or custom field update event. But if I choose a dashboard view event or login event then the code fails to work. I'm very new to this script runner.

Can anyone please let me know how to fire on login event or dashboard event to trigger the action.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import java.sql.Timestamp
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.event.user.LoginEvent
import com.atlassian.jira.event.AbstractEvent
import com.atlassian.jira.event.DashboardViewEvent
import com.atlassian.fugue.Option
import com.atlassian.gadgets.dashboard.Color
import com.atlassian.gadgets.dashboard.Layout
import com.atlassian.jira.bc.JiraServiceContext
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.portal.PortalPageService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.portal.PortalPage
import com.atlassian.jira.portal.PortletConfigurationManager
import com.atlassian.jira.sharing.SharedEntity

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
JiraServiceContext sourceUserServiceCtx = new JiraServiceContextImpl(user)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def issueManager = ComponentAccessor.getIssueManager()
def issue = event.getIssue() as MutableIssue
def event = event as IssueEvent;
def issuetype = issue.getIssueType()
def changeHolder = new DefaultIssueChangeHolder()
class Example{

public DashboardViewEvent(Long dashboardId_10800){

def now = new Timestamp(new Date().getTime())

def cfFuncDate = customFieldManager.getCustomFieldObjectByName("date")
def funcDate = issue.getCustomFieldValue(cfFuncDate)

cfFuncDate.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cfFuncDate),now),changeHolder)


Thanks and Regards,


1 answer

0 votes

If you attempt to run a script listener on the LoginEvent or DashboardViewEvent, the built-in "event" object will not include an issue and the type of event raised will not be an IssueEvent

So these two lines will not work:

def issue = event.getIssue() as MutableIssue
def event = event as IssueEvent

I'm not clear how you expect the system to know against which issue such custom field changes should be done when a user is just logging in and could be accessing any part of the application or when viewing a dashboard that would contain many different gadgets with possibly many hundreds of issues associated with those gadgets.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence Cloud

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

54 views 1 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you