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

differentiate events initiated by api or gui

Hi I use scriptrunner in jira. I created listener with some functionalities, when issue created. If I create issue by jira gui  it works fine.
I have problem, when I create issue by api etc. (by python), my listener works again, but I don't want it. What solution will you suggest?

3 answers

1 accepted

0 votes
Answer accepted

Try to differentiate your issues created by API and through GUI by some field value and use that as a condition in your listener to either skip or process . 

Example:

If you are using a BOT account for API , and create the issue with the BOT user as reporter , you can use that as a condition .

OR

In summary , have a prefix like [ Automation ] < summary goes here > for API created issues and use it as a filter .

Ok. Thank you so much!!! 

Hi @Mamikon Papikyan 

Or... rather than having two pieces of information in the Summary field (source and summary), consider using a different field to indicate the source, such as Labels, Components, or a custom field.  That will make searches, analysis, and updates easier in the future.

Best regards,

Bill

Like Mamikon Papikyan likes this

Hi @Bill Sheboy , thank you. This solution is nice too.

How can I differentiate whether issueEvent raised is because of some transition made using UI or it is made by API call.
I need to make 3rd party call only when transition get updated by UI not by API

Your api call must have a user-id . You can capture logged-in user name and compare if it's the api-user or an actual UI user .

 

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name

def apiUser = "bot"

if ( currentUser == apiUser ){
// exit
}
else {
// execute 3rd party call
}

 

if jira is logged in and API action is performed.
Will 

ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name

give actionable user?

Your API user authenticates first and perform any action thereafter . Any action performed by that user can be captured as I mentioned above .

String loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getName();

It always return the logged in user and not the API user who performed action.
There are possibility, that jira is logged in and transaction is performed  with different user from the app, also name string of users can be same and it can be set of unknown that can't be hard coded as 

def apiUser = "bot"

Is there any call that clearly gives idea that this event creation is via a UI call?

I'm not sure what do you mean by "Jira is logged in ". Jira will be logged in by many users at any given time , but above function will get you the user who performed the action (it can be api user or any other user).

 

If you run the above code in console , it will always return the user name you are currently logged in . If the same code gets triggered by an even it will return the api user which triggers that. 

 

getName() or getKey() gets you the user-id which should be unique . it's the getDisplayName() function that gets you the full name which can be many.

 

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getKey()

 

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getName()

 

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getDisplayName()

Thanks for the reply.

We have SSO configured were in, when an user logs in our app, he gets log-in in jira.
At that point of time, our API user and jira user are same.


Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Jira

Announcing the waitlist for Jira Work Management

Hey there Cloud Community members! We’re excited to give you the first glimpse of the new home for business teams on Jira — Jira Work Management. Jira Work Management is the next generation of J...

640 views 10 16
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