Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

I want to automatically register a component representative in the user selector field

Edited

Hello
I'm going to use Scriptrunner's post function function.
When the status changes after the ticket is issued, I want to automatically register the user with the user picker by putting the person in charge of the component in the user picker.

Is this possible? below is the script.

 

package com.onresolve.jira.groovy.test.scriptfields.scripts
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.user.ApplicationUser

def log = Logger.getLogger("com.acme.curvc")

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def componentManager = ComponentAccessor.projectComponentManager

def userCf = customFieldManager.getCustomFieldObject(12823L) // Developer
def component = issue.componentObjects.toList()
def leadUser = component.componentLead.username

log.debug("test : " + leadUser[0])


if(component.size() == 1){
issue.setCustomFieldValue(userCf, leadUser[0])
}
else if(component.size() > 1){
issue.setCustomFieldValue(userCf, leadUser[0])
}
else{
return "none component"

 

 

1 answer

0 votes

This is absolutely possible, but you have to put it early in the post functions (before "Creates the issue originally").

Try it this way instead:

package com.onresolve.jira.groovy.test.scriptfields.scripts
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.user.ApplicationUser

def log = Logger.getLogger("com.acme.curvc")

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def componentManager = ComponentAccessor.projectComponentManager

def userCf = customFieldManager.getCustomFieldObject(12823L) // Developer
def components = issue.components


if(components){
issue.setCustomFieldValue(userCf, components.first().componentLead)
if(components.size() == 1){
log.info "Single component selected: applied ${components.first().componentLead.name} to Developer field"
} else {
log.info "Multiple component selected: applied ${components.first().componentLead.name} to Developer field (lead for first component)"
}
}
log.info "No component selected"
}

@Peter-Dave Sheehan Thank you for your reply Peter.

finally I resolved it.

Suggest an answer

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

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

533 views 1 10
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