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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

IMMANUEL I'm New Here Jul 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

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
Community showcase
Published in Opsgenie

Investigate deployment-related incidents with Bamboo and Opsgenie together

Back in April of last year one of the major product announcements from Opsgenie was the launch of the Incident investigation view which created a deep connection between Bitbucket and Opsgenie, empow...

149 views 1 4
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