Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

compare logged in user to username in post function

I am trying to compare the current logged in user during a post function to verify that the transition isn't running via an automation.  The automation is set to run as xyz user.  So if the user executing the transition matches that username I don't want to assign the current user to the assignee.  If the current user doesn't match the username then I want to assign the currently logged in user as the assignee.  This is what I have been trying unsuccessfully.  

 

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

if (user != userManager.getUserByName("xyz"))
{

def validateAssignResult = issueService.validateAssign(user,issue.id, user.username)
if(validateAssignResult.isValid()){ issueService.assign(user,validateAssignResult) }
}

 

I look at what the step in the post functions return when I run it manually and it appears to have the correct information but the assignee doesn't update.  I am new to Jira and Groovy so any help will be appreciated.

2 answers

So I have this working with minimal testing -  

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def userManager = ComponentAccessor.getUserManager()
def User = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()

//def Issue issue = issue
if (User != userManager.getUserByName("xyz"))
{
issue.assignee = User
}

 

 

But this does not-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def issueService = ComponentAccessor.issueService
def userManager = ComponentAccessor.getUserManager()
def User = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()

//def Issue issue = issue
if (User != userManager.getUserByName("xyz"))
{

def validateAssignResult = issueService.validateAssign(user,issue.id, user.username)
if(validateAssignResult.isValid()){ issueService.assign(user,validateAssignResult) }
}

 

 

So it would appear that my (validateAssignResult.isValid()) is failing.

Is this a check that is bestPractice?  It seems to me that it would be.  Why is it failing? 

0 votes
Payne Community Leader May 05, 2020

Your code works fine for me in the Script Console (though note in your second listing you define User with a capital "U" and then use it with a lowercase "u"; they should match). Perhaps your post function should be moved up/down in the list of post functions?

After I fixed the case of the U it is logging teh change to history but not actually changing the assignee.  I've moved it around in the post function order and that doesn't seem to change anything.  I have an update change history step and an re-index step in the post function.  It is currently first in the postfunction order.  Code is below

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()


if (user != userManager.getUserByName("SA-PItseJiraAdmin"))
{
def validateAssignResult = issueService.validateAssign(user,issue.id,user.username)
if(validateAssignResult.isValid()){issueService.assign(user,validateAssignResult)}

}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

196 views 6 7
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