[c.o.scriptrunner.runner.ScriptRunnerImpl] Update of user failed

Deactivating Jira Users as per Adaptavist Documentation, seems not working.

Error as below.

Any thoughts appreciated.

017-08-14 16:37:55,812 https-jsse-nio-8443-exec-22 INFO lokesh 997x2622x1 1odkufb 10.95.137.156 /secure/admin/EditService!default.jspa [c.a.j.web.tags.TextTag] An empty i18n key was provided in /secure/admin/views/services/editservice.jsp
2017-08-14 16:37:55,815 https-jsse-nio-8443-exec-22 WARN lokesh 997x2622x1 1odkufb 10.95.137.156 /secure/admin/EditService!default.jspa [w.view.taglib.IteratorTag] Value is null! Returning an empty set.
2017-08-14 16:40:00,053 Caesium-1-1 WARN anonymous    DeactivateUsers [c.o.scriptrunner.runner.ScriptRunnerImpl] Add a script root for this path: D:\JIRA\DeactivateScript.groovy
2017-08-14 16:40:00,848 Caesium-1-1 ERROR anonymous    DeactivateUsers [c.o.scriptrunner.runner.ScriptRunnerImpl] Update of fongyantan failed: 
2017-08-14 16:40:00,848 Caesium-1-1 ERROR anonymous    DeactivateUsers [c.o.scriptrunner.runner.ScriptRunnerImpl] Update of cynthiachoo failed:

Change the final line from
log.error "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}"
to
log.error "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection()}"

Do you get a better error?

Hi,
Have you resolved the problem?

Hello @sfbehnke,

I’m trying to deactivate the users with the above script and i got the same error as you mentioned changed the code with the below lines.
${updateUserValidationResult.getErrorCollection()}"

Now i got the different error.
Error Messages: [Cannot edit user, as the user’s directory is read only.]

Could you please help me with this.

Thanks,
Manikanta

@manikata.chinthapall, you should create new posts for new questions. This is an old thread.

The error message provided is probably accurate – You’re trying to edit a user in a read-only directory. The exact method used in the KB article you’re following won’t work for you in this case.

I can guess what to do next – But this is STILL dependent on how you have set up your Directory Integration, so I may be wrong. IF you’re using a ‘Read-Only Directory with Local Groups’ and your License Group is jira-users, then this method may work –

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes

import org.apache.log4j.Level
log.setLevel(Level.INFO)

def numOfDays = 90 as int
def dateLimit = ( new Date() ) - numOfDays

def groupManager = ComponentAccessor.groupManager
def crowdService = ComponentAccessor.crowdService
def userManager = ComponentAccessor.userManager
def userUtil = ComponentAccessor.userUtil

def const_groupname = 'jira-users'
def group = groupManager.getGroup(const_groupname)
def groupMembers = groupManager.getDirectUsersInGroup(group)

def counter = 0 as int
groupMembers.each{ applicationUser ->
    
    if( applicationUser.isActive() ){
        def user = crowdService.getUserWithAttributes( applicationUser.name ) as UserWithAttributes
        def lastLoginMillis = user.getValue('login.lastLoginMillis') as String
        
        if( lastLoginMillis?.isNumber() ){
            def date = new Date(Long.parseLong(lastLoginMillis)) as Date
            if( date.before(dateLimit) ){
                counter++
                userUtil.removeUserFromGroup(group, applicationUser)
            }
        } else if (!lastLoginMillis) {
            counter++
            userUtil.removeUserFromGroup(group, applicationUser)
        }
    }
}

log.info "Removed ${counter} users"
1 Like

Hello @sfbehnke,
Thanks a lot!
Its working i forgot to change the group name in the script. But it is not deactivating the users who are never logged in.
Any idea on how to do this?

Thanks,
Manikanta

It’s not very clean but for you I added a check for null values, when checking lastLoginMillis.

else if (!lastLoginMillis) {
    counter++
    userUtil.removeUserFromGroup(group, applicationUser)
}

I’ve changed the script as you suggested. It’s not working. Below is the script which I’ve modified.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes

import org.apache.log4j.Level
log.setLevel(Level.INFO)

def numOfDays = 90 as int
def dateLimit = ( new Date() ) - numOfDays

def groupManager = ComponentAccessor.groupManager
def crowdService = ComponentAccessor.crowdService
def userManager = ComponentAccessor.userManager
def userUtil = ComponentAccessor.userUtil

def const_groupname = ‘jira-software-users’
def group = groupManager.getGroup(const_groupname)
def groupMembers = groupManager.getDirectUsersInGroup(group)

def counter = 0 as int
groupMembers.each{ applicationUser ->

if( applicationUser.isActive() ){
    def user = crowdService.getUserWithAttributes( applicationUser.name ) as UserWithAttributes
    def lastLoginMillis = user.getValue('login.lastLoginMillis') as String
               
            else if (!lastLoginMillis) {
counter++
userUtil.removeUserFromGroup(group, applicationUser)

}

        }
    }
}

}

log.info “Removed ${counter} users”