Script Runner Rename User Script only changes internal directory groups?


I was working on adapting the existing Rename User script for JIRA 6.3  I got it working, to some extent, but something odd came up in doing some changes that explains a bug that we've had to workaround in the past:


gvs = gd.findByAnd("Membership", [childName: sourceUser, directoryId: 1, membershipType: "GROUP_USER"])
msg = "Update ${gvs.size()} Membership records"
msgs << msg
if (!preview) {

    List<GenericValue> targetGvs = gd.findByAnd("Membership", [childName: targetUser, directoryId: 1, membershipType: "GROUP_USER"])
    List<Object> targetGroups = targetGvs*.get("parentName")

    gvs.each {GenericValue gv ->
        if (doMerge && targetGroups.contains (gv.get("parentName"))) {
        else {
            gv.set("childName", targetUser)
            gv.set("lowerChildName", targetUser)

It's the segment that reassigns the groups in the script.  It seems to only reassign the membership rows that have directoryId 1, and I'm not 100% sure why?  I've finished adapting the script for JIRA 6.3 (with a few bugs, still, but it's functional, code is here) and I removed the directory mention, I'm just unsure whether i've broken something in the process?

Maybe it's to avoid bugs when merging users in different directories?



1 answer

Hi Eric!

I see that your script contains the variable "directoryId: 1" on multiple lines. Have you tried removing this or changing to the external directory's ID?

Also, please check your directories settings to see if  JIRA has "Read/Write" permission or "Read-only with local groups".



Hi Joao, I'm not trying to troubleshoot a bug here. I'm not having any significant problems with my script. I was just asking why the script was written that way in the first place, as I didn't write it, it's a segment from the rename user script that Jamie Echlin wrote. Eric

The example code you got is a bit old and it is using deprecated classes. That was the probably the way of achieving this in Jira 4/5, but I'm sure there is a better way to do it with the new managers and services provided in the newest Jira API versions

Hi Alejo, Again, that's completely beside the question that I'm asking here. I'm aware that the classes are deprecated. It wasn't written by me and hasn't been updated since jira5 (at least). I'm simply asking if there is a specific reason why only the internal directory is changed in the script, is it to avoid a bug/issue of which I'm still unaware? I've actually done some adjustments in the live code that I'm using in order to avoid the deprecated classes and methods, this is the original code from the plugin that I'm posting here as a reference. Eric

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

202 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you