Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with Scriptrunner code

Rajesh Kumar April 19, 2022

I Have 2 single select custom field.

Ex: Field1 : (1,2,3,4,5) as drop down values

    Field2 : (A,B,C,D,E) as drop down values

Based on selection of above fields, Priority System field as to be set as defined.

For Ex: if Field1 = 1 && Field2 = A, Priority to be set as High

               Filed1 = 2 && Field2 = B, Priority to be set as Medium

               Filed2 = 3 && Field2 = C, Priority to be set as Low ------etc.

as a start, i have tried with following code applied at post function of create transition,

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.PriorityManager


final cFieldName = "Testing Select Field"

//Get custom field issue with this name
def customFieldManager = ComponentAccessor.customFieldManager
def cField = customFieldManager.getCustomFieldObjects(issue).findByName(cFieldName)
def sField = customFieldManager.getCustomFieldObjects(issue).findByName(sFieldName)

def priorities = ComponentAccessor.getComponent(PriorityManager).priorities

def HighestId = priorities.findByName("Highest").getId()

if (cField.getValue(issue) == 1){
issue.setProjectId(HIghestId)
}

 

Please help me on it.

 

Thanks in Advance

1 answer

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 19, 2022

Welcome to the Atlassian Community!

It looks like you've copied really bad code from somewhere, could you have a look through https://library.adaptavist.com instead?  A simple search for priority should get you there, last time I looked, I think I saw an "update priority field from custom field" example

Suggest an answer

Log in or Sign up to answer