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

0 votes

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
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,645 views 18 21
Read article

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