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

How assign a value to a custom field?

Shah Baloch October 30, 2020

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

Comment

Log in or Sign up to comment
Shah Baloch October 30, 2020

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 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
Shah Baloch November 3, 2020

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 3, 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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 4, 2020

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

TAGS
AUG Leaders

Atlassian Community Events