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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,464,570
Community Members
 
Community Events
176
Community Groups

Using ScriptRunner to Assign Approver based on Amount Value

Custom Field : Amount

If Amount >= $1000 Then Approver = John

If Amount < $1000 Then Approver = Jill

Trying to get this into my workflow.  Any suggestions?

Thanks.

1 answer

0 votes

Hi Michael,

Assuming your 'Amount' field ID is 11111 and your 'Approver' field ID is 22222, your script should look something like this:

import com.atlassian.jira.component.ComponentAccessor

def usrMgr = ComponentAccessor.getUserManager()
def cfMgr = ComponentAccessor.getCustomFieldManager()
def amount = cfMgr.getCustomFieldObject(11111.toLong())
def approver = cfMgr.getCustomFieldObject(22222.toLong())
def userJohn = usrMgr.getUserByName("John's user name")
def userJill = usrMgr.getUserByName("Jill's user name")

if (issue.getCustomFieldValue(amount) >= 1000){
issue.setCustomFieldValue(approver, userJohn)
}else if (issue.getCustomFieldValue(amount) < 1000){
issue.setCustomFieldValue(approver, userJill)
}

Is there documentation somewhere on how I should properly test this?  Can I do it from the ScriptRunner console or do I have to do it from an actual issue?

 In my instance I have a test project to play around with safely.

I suppose you can also do it in ScriptRunner console on a dummy issue, but you'll need to declare your 'issue' variable for that:

def issue = ComponentAccessor.getIssueManager().getIssueObject("test issue key")

I'm sorry Approver = the built-in Jira assignee field

then use this:

issue.setAssignee(userJohn)

Gives me unable to resolve class com.atlassian.jira.component.componentAccessor.

I am using Jira Cloud if that matters.

it should be exactly like this (case sensitive):

import com.atlassian.jira.component.ComponentAccessor

It is exactly like that.

Workflow Post Functions | Run Script | Run arbitrary code on transition

and then I copied the code to the Script Context section

Hi , how to add more than one approver in list based on condition, Please help.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events