script behavior

Manoj March 10, 2023

Hi Mates, 

sharing below script to autofill custom fields based on specific role defined, this does throw any error but when i am filling the specific field other custom fields does get auto fill.

kindly suggest

 

import com.atlassian.jira.component.ComponentAccessor

def cfSpecificRole = getFieldById("customfield_23606")
def cfStandardizedrole = getFieldById("customfield_23605")
def cfNextLevelCategory = getFieldById("customfield_24654")
def cfBroaderCategory = getFieldById("customfield_24652")

def optionsManager = ComponentAccessor.getOptionsManager()

if(cfSpecificRole.getValue()=="Developer-MS")  {cfStandardizedrole.setFormValue("MS/API BE Developer")} {cfNextLevelCategory.setFormValue("Developers")} {cfBroaderCategory.setFormValue("Development")}
else if(cfSpecificRole.getValue()=="Developer-Apigee")  {cfStandardizedrole.setFormValue("MS/API BE Developer")} {cfNextLevelCategory.setFormValue("Developers")} {cfBroaderCategory.setFormValue("Development")}


1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 12, 2023

Hi @Manoj ,

please specify type of your custom fields. Method getValue return different objects depending of cf types.

Take a look here for more information about getValue https://docs.adaptavist.com/sr4js/latest/features/behaviours/api-quick-reference

Moreover, also setFormValue is impacted by types.

Fabio

Manoj March 12, 2023

@Fabio Racobaldo _Herzum_ hi, custom fileds are text type has list of options which contains types of job roles. 

I have done this automate role pickers in custom fields by breaking the script. 

 

Earlier I was trying to achieve by writing one line. For example if I select Say role Developer-BE (in custom field - Specific role) then it would update Standarized role, next level catergory and broader category. 

And that did not work. 

 

Now what I did, if Specific role is Developer-BE then it would update standardized role

 

And if Standardized role is MS/BI developer then it woud update next level category and similarly so on. 

 

And it worked and updating roles in other custom fields if specific role is updates. 

 

Do you other way to do this? 

To be precise. 

If I fill custom field 1 then based on inputs in custom field 1, custom field 2 , custom field 3 will pick up their values. 

 

Thnks

Suggest an answer

Log in or Sign up to answer