We have 289 users currently, and have been told that for integration purposes we need to now create a User Property for each of them that holds their email alias without the @domain.com piece due to special character issues. Rather than have to update all 289 of them manually one by one, I'm hoping to script something up.
This is what I've gotten so far based on what I've found in forums and online. I believe my issue is related to the fact that I'm not getting an ApplicationUser as I iterate through the userList collection, and then I have an error on the getPropertySet() that I can't decipher.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.util.UserUtil import com.atlassian.jira.user.util.UserManager UserUtil userUtil = ComponentAccessor.getUserUtil() def userPropertyManager = ComponentAccessor.getUserPropertyManager() def userManager = ComponentAccessor.getUserManager() def userList=[UserManager.getAllApplicationUsers()] def email userList.each { thisUser -> email = thisUser.getEmailAddress() userPropertyManager.getPropertySet(thisUser.getName()).setString("jira.meta.Alias",email.substring(0, email.indexOf('@'))) }
and the error message:
2017-06-23 17:33:36,795 WARN [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.user.util.UserManager.getAllApplicationUsers() is applicable for argument types: () values: [] at Script80.run(Script80.groovy:8)
Hi Blake.
I think you should do this:
def userPropertyManager = ComponentAccessor.getUserPropertyManager() def userManager = ComponentAccessor.getUserManager() def userList=UserManager.getAllApplicationUsers() def email userList.each { thisUser -> email = thisUser.getEmailAddress() userPropertyManager.getPropertySet(thisUser.getName()).setString("jira.meta.Alias",email.substring(0, email.indexOf('@'))) }
Without the brackets around the user manager, the script will give you a red at the start of the closure, but in execution time it should work properly. If you want to avoid the red you could do this:
def userPropertyManager = ComponentAccessor.getUserPropertyManager() def userManager = ComponentAccessor.getUserManager() Collection<ApplicationUser> userList=UserManager.getAllApplicationUsers() def email userList.each { thisUser -> email = thisUser.getEmailAddress() userPropertyManager.getPropertySet(thisUser.getName()).setString("jira.meta.Alias",email.substring(0, email.indexOf('@'))) }
Hope this helps!
Cheers!
Dyelamos
Thanks Dyelamos! I've tried both methods, but unfortunately am still getting the same error (for both methods):
Logs:
2017-06-26 10:32:40,572 WARN [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.user.util.UserManager.getAllApplicationUsers() is applicable for argument types: () values: [] at Script95.run(Script95.groovy:8)
Result:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh boy :D
I just realised, that you are calling
UserManager, (first letter is a capital, which is a global variable)
insted of
userManager, (first letter undercase) which is the variable you get line 3.
Apologies for missing that. Your script should look like this:
def userPropertyManager = ComponentAccessor.getUserPropertyManager() def userManager = ComponentAccessor.getUserManager() def userList=userManager.getAllApplicationUsers() def email userList.each { thisUser -> email = thisUser.getEmailAddress() userPropertyManager.getPropertySet(thisUser.getName()).setString("jira.meta.Alias",email.substring(0, email.indexOf('@'))) }
Cheers!
Dyelamos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Dyelamos - that would have driven me crazy!
I was able to finally get it to work with your script by changing
userPropertyManager.getPropertySet(thisUser.getName()).
to
userPropertyManager.getPropertySet(thisUser)
thanks again for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem. Please accept my answer so that people know this has been answered!
Cheers
Dyelamos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Daniel Yelamos [Adaptavist]
This helped me.
I think though that there've been some changes since you submitted that code, so here is the latest code that I used. However, my requirement was to remove the users "autowatch" preferences and let it inherit the settings:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
UserUtil userUtil = ComponentAccessor.getUserUtil()
def userPropertyManager = ComponentAccessor.getUserPropertyManager()
def userManager = ComponentAccessor.getUserManager()
def userList= userUtil.getUsers() //UserManager.getAllApplicationUsers()
def email
def username
userList.each { thisUser ->
def propertySet = userPropertyManager.getPropertySet(thisUser)
propertySet.remove("user.autowatch.disabled")
}
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.