Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Change user properties from scriptrunner custom field

Hi community!

With help of ScriptRunner I created custom filed(Text Field multi-line) that shows the user properties of the issue reporter

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserPropertyManager

UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager()

String propValue = null


propValue = userPropertyManager.getPropertySet(issue.reporter).getString('jira.meta.More')

return propValue

Is it possible to add a function for changing properties in this field, and how can this be done?
I have little knowledge in Scriptrunner, Thanks in advance.

 

1 answer

0 votes

Hi @Vladimir_Fed ,

A. If I understood it correctly, you want to save the reporter's user property in your newly created custom field?

OR 

B. Whatever the value of the newly created custom field it will save it to the user property of the issue reporter?

 

Hi @brbojorque 

Probably option B

Now the custom field returns the user properties that I added in user management (ex. Key = More)
I want the user’s properties to be changed through the current custom field and saved, even if they are already specified there.

Hi @Vladimir_Fed ,

Here's the ScriptRunner Listener code

Remove the old custom field and create a new custom field from Jira.

Make sure it will listen to Issue Created and Issue Updated

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserPropertyManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser

UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager()

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userPropertiesField = customFieldManager.getCustomFieldObjectByName("User Properties") //Multi line custom field

MutableIssue issue = (MutableIssue) event.issue

//Saving the property Preferences
userPropertyManager.getPropertySet(issue.reporter).setString('jira.meta.more', issue.getCustomFieldValue(userPropertiesField) as String)

//Reading the property
String propValue
propValue = userPropertyManager.getPropertySet(issue.reporter).getString('jira.meta.more')

//Saving the property to Custom Field
issue.setCustomFieldValue(userPropertiesField, propValue)
ApplicationUser applicationUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(applicationUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Out of curiosity what is the reasoning behind this requirement? 

-

Hi, @brbojorque 

Thanks a lot, but code doesn't work.

Screenshot_2.jpgScreenshot_3.jpgThese are support B2B requirements for Service Desk.

They need the ability to change the contact details of customers, provided that they have the rights of only an  SD agent

brbojorque Community Leader Jan 05, 2020

Hi @Vladimir_Fed ,

You can't actually change the User data by just changing the preferences. 

E.g Username, Last name, first name.

I believe this solution is not for you.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Desk

The Complete Guide to Atlassian for ITSM

Hi Atlassian Community! This is Teresa from the Atlassian team. My colleague Paul Buffington @Buff and I are excited to share a brand new ITSM resource we’ve created – "The Complete Guide to At...

2,245 views 14 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you