We're using JIRA 6.3.7
Is there any possibility to update custom User Properties (via API or via Script)?
I want to add new properties and update the values of existing ones.
I'm referring to these properties:
Clipboard_1.png
I want to avoid updating it via SQL script executed on the JIRA database, but I cannot find any documention regarding the supported APIs or scripts. It seems that database update is the only possible way.
Thank you in advance for your help!
Community moderators have prevented the ability to post new answers.
You can use script-runner and doing something like that
import com.atlassian.jira.component.ComponentAccessor def userPropertyManager = ComponentAccessor.getUserPropertyManager() def userManager = ComponentAccessor.getUserManager() def admin = userManager.getUserByName("admin") userPropertyManager.getPropertySet(admin).setString("jira.meta.myproperty","123")
The prefix "jira.meta." is imporant, if you don't use this convention new properties will not be shown on that section (the form on your screenshot).
Cesare,
If I wand to add a property to all users, where do I put this script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@cesare I was hoping you could provide a solution similar to this one above. I need to update all user's properties that are part of a specific group.
import com.atlassian.jira.component.ComponentAccessor
def userPropertyManager = ComponentAccessor.getUserPropertyManager()
def userManager = ComponentAccessor.getUserManager()
def groupManager = ComponentAccessor.getGroupManager()
def users = groupManager.getUsersInGroup("Testing")
for (user in users) {
userPropertyManager.getPropertySets(user).setString("jira.meta.myproperty","123")
}
This is what I have now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all!
I adapted @Cesare Jacopo Corzani to a small ScriptRunner REST Endpoint to update legacy user properties thru URL query params (_https://yourjira/rest/scriptrunner/latest/custom/updateUserProperty?value=12345678&username=some-user&property=abc_): https://gist.github.com/andreyev/94bd402cdcc41ef4166f5abf97bd43da
Hope it helps!
–
Andreyev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In combination with Postman you can update the user properties in bulk with a csv file
https://www.getpostman.com/docs/multiple_instances
Before JIRA 7 i used the JIRA CLI but this isn't free anymore. With this snippet i can replace this and with the csv it's better than before.
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cesare,
I have a code that gets the values, but I cannot find a way to update them in system when I want to insert new values.
So this piece gets the data:
import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.UserPropertyManager String propertyKey = "xxx" String propertyValue = null UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager() User u = issue.reporter if (u) { propertyValue = userPropertyManager.getPropertySet(u)?.getString('jira.meta.'+propertyKey) } return propertyValue
and this piece updates the values directly in the database (but this is something I consider as a hack, not a official supported method).
Another thing is that the values are updated, but they are not refreshed instantly, it's something related to the JIRA cache.
import groovy.sql.Sql import java.sql.Driver import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.UserPropertyManager def driver = Class.forName('org.postgresql.Driver').newInstance() as Driver def props = new Properties() props.setProperty("user", "xxx") props.setProperty("password", "yyy") def conn = driver.connect("jdbc:postgresql://localhost:5432/jira", props) def sql = new Sql(conn) ... some code ... try { sql.executeUpdate("update propertystring set propertyvalue = $newValue WHERE id = (SELECT id FROM propertyentry WHERE property_key = $propertyKey AND entity_id = (SELECT id FROM app_user WHERE user_key = $userLogin))") } finally { sql.close() conn.close() }
Thank you for your answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is the method setString I suggested before not working?
If you use that on the PropertySet, Jira should save the data for you without using the DB hack.
with :
userPropertyManager.getPropertySet(admin).setString("jira.meta.myproperty","123")
You should have an implicit insert/update. I've tried it before posting the solution and after executing that line I had entries on the section you were referring to. Isn't it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem, you are welcome.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.