Forums

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

Extract substring from fields, convert to numbers, multiply and set the value of another field

Jemima James July 14, 2022

I have a custom field (list) A, with values as follows:

1 - Unlikely, 2 - Low likelihood, 3 - Likely, 4 - Very likely, 5 - Near certainty

I have another custom field (list) B, with values as follows:

1 - Minimal, 2 - Minor, 3 - Moderate, 4 - Major, 5 - Unacceptable

Whenever user changes the field value, I need to do the below:

  1. Extract the number part of these two fields
  2. Multiply these numbers
  3. Based on the value, set another custom field C value to either X, Y or Z (eg if the product is between 12 and 20 then set C to "X".

How do I achieve this?

  • Can this be done using automation and smart values? If yes, please help me out with the smart value for setting custom field C
  • Can this be done using Scriptrunner? If yes, please help me with the script code (i am a newbie so please include the packages to import for the code)

Note:

  • This should work no matter how many times A or B value is changed during an issue updation.
  • I am using data center version, which means that I don't have the option to create 'variables' in JIRA automation

2 answers

0 votes
Gaurav
Community Champion
July 15, 2022

Hello @Jemima James 

This makes an interesting scenario, due to the limitation in the data centre versions, where variables cannot be defined. Having said that, we can still achieve this with the following steps:

  • Set the trigger to field value change for Custom Field A and Custom Field B
  • Next, define the 'If Else' construct, checking the value of Custom Field A and Custom Field B
  • Since the values for Custom Field A and Custom Field B are pre-defined, we can create a matrix for the value of Custom Field C. This can be used to set the value.

 

For example:

Considering the below matrix, we can set the rule.

Matrix.PNG

 

If Field A = "1 - Unlikely" and Field B in (1 - Minimal, 2 - Minor, 3 - Moderate, 4 - Major, 5 - Unacceptable) --> THEN  --> Set Field C as X

 

Kindly accept the answer if this helps. please feel free to reach out in case of any further queries.

 

Regards,

--GG

0 votes
Janco Hoekstra July 15, 2022

Using scriptrunner you can use something like:

class Example { 
   static void main(String[] args) { 
      def singleSelectField1 = ComponentAccessor.customFieldManager.getCustomFieldObject(10402) // id of the CF substitute with your first field
def singleSelectFieldValue1 = issue.getCustomFieldValue(singleSelectField)
def numpart1 = singleSelectFieldValue1.substring(0,0)).toInteger(); def singleSelectField2 = ComponentAccessor.customFieldManager.getCustomFieldObject(10402) // id of the CF substitute with your second field
def singleSelectFieldValue2 = issue.getCustomFieldValue(singleSelectField)
numpart1 = singleSelectFieldValue1.substring(0,0));
def numpart2 = singleSelectFieldValue1.substring(0,0)).toInteger();

def product = numpart1 * numpart2


} }

to extract the number part of the list fields and multiply the results. After that it is simply maken an if-then constuction to determen the letter and after that write this to the target field. 

Suggest an answer

Log in or Sign up to answer