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

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

IMMANUEL July 27, 2020

Hi,

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
com.atlassian.jira.event.user.UserEvent
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.issue.search.SearchRequest
import com.atlassian.jira.issue.search.SearchRequestManager
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,

Imman

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 27, 2020

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.

TAGS
AUG Leaders

Atlassian Community Events