Hi @Mt4 ,
your code brought me forward and I finished it updating the Component. Using the ProjectComponentManager to update the component is required at the end:
def projectComponentManager = ComponentAccessor.projectComponentManager
projectComponentManager.update(newProjectComponent)
But there are two additional points to take into account:
1. The Component you copy must be the new component which shall be updated. Dependant on what components.each loops through, you maybe need to change it. If eachComponent is the source, then you will update the source component.
MutableProjectComponent newProjectComponent = MutableProjectComponent.copy(eachComponent);
2. the Parameter for setLead is a String but the String should match an existing username.
newProjectComponent.setLead("username")
following this it worked for me.
regards
Christoph
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried replacing a component with the below code. But nothing works:
This code tries to fetch a component from a user and replace the lead. Instead the field is left blank in the component.
//variable declaration for adding groups and projects
def userManager = ComponentAccessor.userManager
def projectManager = ComponentAccessor.projectManager
def userService = ComponentAccessor.getComponent(UserService)
def projectComponentManager = ComponentAccessor.projectComponentManager
String printtext
@UserPicker(label = 'New project lead', description = 'Enter a project lead to set for this project')
ApplicationUser user
def components = projectComponentManager.findComponentsByLead(user.getUsername())
for(int c=0;c<components.size();c++)
{
MutableProjectComponent newProjectComponent = MutableProjectComponent.copy(components[c]);
newProjectComponent.setName(components[c].getName())
newProjectComponent.setLead("dummy_username")
newProjectComponent.setDescription(components[c].getDescription())
newProjectComponent.setAssigneeType(components[c].getAssigneeType())
projectComponentManager.update(newProjectComponent)
}
return components[0].getComponentLead()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Never mind. Got it to work. I had to pass the User Key instead of user name.
Not sure what's going on. It works, so I'll take it XD
Shared the script that works for me in a new comment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mt4 ,
welcome to the Atllassian community!
setLead should have a username as parameter and not a string like "Component Lead Not Identified". A component lead is a user.
Hope this helps,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabio,
I tried with passing users as well, but still its not working.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.