Script Runner change multiple user IDs

Liston Ogana April 9, 2014

I have looked at the script runner "Renames A user ID". How do I go about doing a bulk change of user ID's? I have over 400 user IDs that I need to change.

Thanks

1 answer

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2014

Here's sample. You need to just execute the script in a loop:

def ren = new com.onresolve.jira.groovy.canned.admin.RenameUser();
def input = [ 
	["admin","newname"],
        ["asd", "usernew"]
        ];
def result = ""
for (e in input) {
	def args = [
                   (com.onresolve.jira.groovy.canned.admin.RenameUser.FIELD_FROM_USER_ID): e[0],
        	   (com.onresolve.jira.groovy.canned.admin.RenameUser.FIELD_TO_USER_ID): e[1],
        	    (com.onresolve.jira.groovy.canned.admin.RenameUser.FIELD_MERGE): false
                ];
        result+=ren.getDescription(args, true)
        //Uncomment to actualy execute, the line above is for preview
        //result+=ren.doScript(args)
        
}
result

Liston Ogana April 10, 2014

Thanks for the response Boris. I have tried your script and also the script from this Scott Dudley from this question below

https://answers.atlassian.com/questions/75640/how-can-i-use-the-groovy-runner-jira-user-id-rename-form-the-command-line

The problem I am having is that both scripts are not updating the app_user table in the database. Which is causing the erorr User 'James.Jones' exists but has no unique key mapping.

In Jira 6x you can update the user ID by editing the user in JIRA. This seems to be updating the column lower_user_name in the app_user table. When I run the scripts this is not updated and the way around it is to run these SQL statement and update the app_user table.

https://confluence.atlassian.com/display/JIRAKB/JIRA+Login+Fails+With+the+Message+-+User+exists+but+has+no+unique+key+mapping

INSERT INTO app_user
SELECT (<id from previous query + 1>,
'username_that_caused_error',
'username_that_caused_error'
FROM app_user;
Not sure if there is an easy way around this since I have 400 users and I am uncertain if
adding additional users on the table app_user will cause any problems in the future.
Any information on this will be greatly appreciated.

Suggest an answer

Log in or Sign up to answer