Quantcast
Channel: Active questions tagged atlassian-plugin-sdk - Stack Overflow
Viewing all articles
Browse latest Browse all 280

Write code to change user email address unable to resolve class UserAccessor

$
0
0

I am trying to write code to change a user email address in Jira and I am getting the following error for my last import

unable to resolve class

 com.atlassian.confluence.user.UserAccessor

Anyone knows how this can be fixed? I am using Jira Service Management 5.12.11 and Jira Software 9.12.11. Anyone knows how to fix the problem?

import com.atlassian.sal.api.component.ComponentLocatorimport com.atlassian.jira.issue.fields.CustomField;import com.atlassian.jira.issue.CustomFieldManager;import com.atlassian.jira.user.util.UserManager;import com.onresolve.scriptrunner.parameters.annotation.ShortTextInputimport com.atlassian.jira.bc.user.DefaultUserServiceimport com.atlassian.jira.user.util.UserManagerimport com.atlassian.confluence.user.UserAccessor@ShortTextInput(label = 'File path', description = '\\itrac-tst\\mouh-share\\newMailAddress.txt')String csvFilePathdef userAccessor = ComponentLocator.getComponent(UserAccessor)// Edit the file path below to your user csv file pathdef file = new File(csvFilePath)def csvMapList = []file.eachLine {        // Read each line of a CSV file to form a user map        line ->                def columns = line.split(",")                def tmpMap = [:]                tmpMap.putAt("username", columns[0])                tmpMap.putAt("original_email", columns[2])                csvMapList.add(tmpMap)}log.debug(csvMapList)def accountsUpdated = 0csvMapList.each {        // Iterate through each user in map and update user emails        map ->                def userName = map["username"] as String                def originalEmail = map["original_email"] as String                // Edit new_email to the new domain you want to use                def newEmail = originalEmail.split('@')[0].concat("@new_email.com")                if (userAccessor.exists(userName)) {                        def originalUser = userAccessor.getUserByName(userName)                        def modifiedUser =  UserManager.getUser(originalUser)                        modifiedUser.setEmail(newEmail)                        userAccessor.saveUser(modifiedUser)                        if (userAccessor.getUserByName(userName).getEmail() == newEmail) {                                log.debug("Successfully updated " + userName +"'s email from " + originalEmail +" to " + newEmail)                                accountsUpdated++                        } else {                                log.debug(userName +"'s email was not successfully updated.")                        }                } else {                        log.debug("User " + userName +" was not found.")                }}log.debug("User update completed. Successfully updated " + accountsUpdated +" accounts.")

I have tried to write it in the script console but the import is the problem

1


Viewing all articles
Browse latest Browse all 280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>