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

How assign a value to a custom field?

I'm trying to assign a user to a user picker custom field base on the value of another custom field (dropdown). For example, there are 4 values (Product, Customer, Support, Accounts) in a dropdown field. If the user selects "Product" the user picker custom field should have a user (George), if the user select "Support" from the dropdown then the custom user field should have the value "Parker".  If user select other two options then it should have default value "Mark". I tried but some reason it is just picking the default user "Mark" for all selection. Any idea how to make it work? Following is my behaviour script. Thank you for your help.

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

def custAssignee = 'mark'
def custField = getFieldByName("Inventory")

if(custField.value == 'Product') {
custAssignee = 'george'

}
if(custField.value == 'Support') {
custAssignee = 'parker'

}
def customerAssigneeFormField = getFieldById('customfield_11305')
customerAssigneeFormField.setFormValue(custAssignee)

1 comment

I edited my comment.

There was an issue with lower and upercase. I fix that.

Now I would like to make it work with a single-line text field. Where Users enters a number. For example, if the user enter 1000 or less it should set the user picker field value as george but if the user enter more than 1000 then it should set the user picker field value as Kelly. It was not working with >= <=. Do I have to use a number field or something wrong with code?

Hana Kučerová Community Leader Oct 31, 2020

Hi @Shah Baloch

try something like this (xxxxx needs to by replaced by id of your text custom field):

def userFormField = getFieldById('customfield_11305')
def textFormField = getFieldById('customfield_xxxxx')

Integer number = textFormField.getValue() as Integer

String user = number > 1000 ? 'kelly' : 'george'
userFormField.setFormValue(user)

I recommend you to insert this code as a server-side script to the text field (everytime you change this field you want to update the user field).

Still, I think it would be better to use number field instead of text field, if your users will fill in only numbers.

Like Shah Baloch likes this

Thank you so much @Hana Kučerová it worked.

This thread can be close. Thank you

Like Hana Kučerová likes this
Hana Kučerová Community Leader Nov 03, 2020

Hi @Shah Baloch ,

glad to help :-).

Would you please mark my answer as accepted? This action will mark the question as resolved and it can also help other users in the future to find the solution, if they have similar problems. Thank you!

Hana Kučerová Community Leader Nov 04, 2020

Sorry, I thought this is question (not discussion), my last post doesn't make sense, ignore it, please :-).

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

630 views 7 23
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