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

Scriptrunner post function or behaviour

Always add user (Tom Thomas) as a watcher on an issue if assignee is (John Johnson) in a certain project, for example project ABC. 

Now i only have this code plz help

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def cfManager = ComponentAccessor.getCustomFieldManager()

def cf = cfManager.getCustomFieldObject((Long) 11111)
def user = userManager.getUserByName("username")

if (issue.getCustomFiledValue(cf).equals("value")){
watcherManager.startWatching(user, issue)
}

 

3 answers

1 accepted

Hi @Stanislav

It would be better to use the Post-Function and add a Custom Script to it.

You can try something like this:-

import com.atlassian.jira.component.ComponentAccessor

def watcherManager = ComponentAccessor.watcherManager
def userManager = ComponentAccessor.userManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

if(loggedInUser.name == "John Johnson") {
def watchUsers = { usernames ->
usernames.each {
def user = userManager.getUserByName(it)
watcherManager.startWatching(user, issue.genericValue)
}
}
def users = ["tthomas"] // use Tom Thomas' username not full name
watchUsers(users)
}

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

I hope this helps to answer your question. :)

Thank you and Kind regards,
Ram

@Ram Kumar Aravindakshan _Adaptavist_ But i don't see any assignee script in your code

it is my biggest problem

Hi @Stanislav,

If you want to set the watcher based on the assignee, you can modify the if condition to something like:-

if(assignee.name=="jjohnson") {
.
.
.
}

 Below is the updated working sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor

def watcherManager = ComponentAccessor.watcherManager
def userManager = ComponentAccessor.userManager
def assignee = issue.assignee
def watcher = userManager.getUserByName("tthomas")

if(assignee.name=="jjohnson") {
watcherManager.startWatching(watcher, issue)
}

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram 

Like Stanislav likes this

Or maybe this one that i find

import com.atlassian.jira.component.ComponentAccessor

def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager() 

def user = userManager.getUserObject("userid") 
if (user) watcherManager.startWatching(user, issue.genericValue)

Hi @Stanislav user if statement like below 

issue.get("customfield_12345").getName() = “user name”

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...

193 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