Hi,
I am trying to create a job function to read a csv file and update user properties based on that. I don't want to do it via the REST API because the properties set by the API are not usable in post-function.
I want add the manager of all my users. Those data are present in a csv with 2 columns : user | manager
On the job, the line "
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserPropertyManager
import com.mindprod.csv.CSVReader
def filePath = '/home/jira/atlassian/application-data/jira/scriptrunner/user_test.csv'
def reader = new CSVReader(new FileReader(new File(filePath)))
//Gets the user property value based on the key.
def propertyKey = 'manager'; //Property name
UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager();
def data= reader.collect { it }.with { rows ->
def header = rows.head()
def dataRows = rows.tail()
dataRows.collect { row ->
[header, row].transpose().collectEntries()
}
}
data.each{row->
userPropertyManager.getPropertySet(row.user)?.setString('jira.meta.'+propertyKey, row.manager);
// access any data from the row by the name of the header
// for example, row['colHeader'] or row.colHeader
}
Thanks in advance
Without knowing actually what happens in your environment (errors in the log or anything), this is a bit of a shot in the dark... but try like this:
data.each{row->
def user = ComponentAccessor.userManager.getUserByName(row.user)
if(user){
def props = userPropertyManager.getPropertyeSetForUserKey(user.key)
props.setString("jira.meta.$propertyKey", row.manager)
} else {
log.warn "No Jira user found matching $row.user"
}
}
Hi,
Thank you for the feedback. I think the issue is coming from the data not being retrieve from my csv file because it look likes the getUserByName don't retrieve anything :
No Logs, and the result is an empty array.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to add a bit of logging...
Just above 'def user = ' add:
log.info "Reading row: $row to extract $row.user"
This will hopefully give you some clues.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.