Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,362,135
Community Members
 
Community Events
168
Community Groups

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

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

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
TAGS

Atlassian Community Events