• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


29 Nov, 2024

Updated at 02 Dec, 2024

Calculate Custom Fields values in Scripted Field using Scriptrunner in JIRA Cloud

Hi Community, 

In Jira Cloud, I have two custom fields: Compliance and Audit (Select List - single choice).

I have created two Text Fields (single line): Risk Score and Risk Level which will be used as Scripted Field in Scriptrunner in Jira Cloud.

First, I am writing this below code to calculate the sum of Compliance and Audit and show the result in Risk Score:

def complianceField = "customfield_XXXXX" //Compliance
def auditField = "customfield_YYYYY" //Audit
def result = get("/rest/api/2/issue/${issue.key}")
             .queryString("fields", "customfield_10280,customfield_10281")
             .header('Content-Type', 'application/json')
             .asObject(Map)

String complianceFieldValue = result.body.fields[complianceField]?.value
String auditFieldValue = result.body.fields[auditFieldValue]?.value

def retval = 0
switch (complianceFieldValue) {
              case ('Impacts from 10 and above'):
                             retval+=9;
                             break;
              case ('Impacts from 5 to 10'):
                             retval+=5;
                             break;
              case ('Impacts from 3 to 5'):
                             retval+=3;
                             break;
              default:
                             retval+=0;
                             break;
}
switch (auditFieldValue) {
              case ('Impacts more than 1000 consumers'):
                             retval+=9;
                             break;
              case ('Impacts between 500 consumers'):
                             retval+=5;
                             break;
              case ('Impacts less than 300 consumers'):
                             retval+=3;
                             break;
              default:
                             retval+=0;
                             break;
}
return retval.toString();

But facing Static type checking error in the above code. Please guide further in resolving the issue.