Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

custom user picker based on select list value in postfunction using scriptrunner

Hi,

I want to change value in customfield user picker (single) to specific user based on customfield select List (single) chosen value. In all cases I know which values in select list equal which users in user picker.

It goes on like this:
- if customfield "Category of Issue" = "First Category" or "Second Category" -> change "Responsible Agent" to "John"
- if customfield "Category of Issue" = "Third Category" -> change "Responsible Agent" to "Bob"

3 answers

0 votes
Tarun Sapra Community Leader Aug 14, 2017

This has been discussed many times on this forum.

You first need to fetch the values of user pircker field and then update the drop-down field's value.

Here's an sample - https://community.atlassian.com/t5/JIRA-questions/Updating-a-custom-field-using-groovy-script-runner/qaq-p/256708

Thank you @Tarun Sapra, however none of examples provided includes following logic:


if in field is this OR this selected = change this user picker field to this user

Below is custom script, however it gives an error.
I used similar script (without if statement) for Fast-track transition, where it worked.
I placed custom script after "Fire a" event in post function.

Can you kindly advise why custom script is not working?

JIRA v7.3

Custom Script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.IssueManager

IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField CF = customFieldManager.getCustomFieldObjectByName("Responsible Agent Team");
def userManager = ComponentAccessor.getUserManager()
def user_tier2engineer = userManager.getUserByName("sst2engineer")
def user_tier2specialist = userManager.getUserByName("sst2specialist")

if (cfValues['IT / Casino Issue Category']?.value == 'Internal game issue'){
issue.setCustomFieldValue(CF, user_tier2engineer);
}
else { issue.setCustomFieldValue(CF, user_tier2specialist);
}


ERROR:

2017-08-21 11:07:04,224 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-08-21 11:07:04,236 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SD-903, actionId: 241, file: <inline script>
groovy.lang.MissingPropertyException: No such property: cfValues for class: Script275
at Script275.run(Script275.groovy:20)

 


Fast-track transition script that works:

Condition:
cfValues['IT / Casino Issue Category']?.value == 'Internal game issue'

Additional issue actions:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor


IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField CF = customFieldManager.getCustomFieldObjectByName("Responsible Agent Team");
def userManager = ComponentAccessor.getUserManager()
def user_tier2engineer = userManager.getUserByName("sst2engineer")
issue.setCustomFieldValue(CF, user_tier2engineer);

Thanks in advance! 

I enjoy woodworking in my spare time and have by chance turn out to be a hobby community engineer after figuring out to do a self set up of some diy like gclub protection systems.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

All you wanted to know about customer support KPIs

When working in customer support, it’s crucial to calculate, analyze and monitor specific numbers, called KPIs (Key Performance Indicators). They go hand-in-hand with customer satisfaction, problem d...

45 views 1 2
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