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_XXXXX,customfield_YYYYY")
.header('Content-Type', 'application/json')
.asObject(Map)
String complianceFieldValue = result.body.fields[complianceField]?.value
String auditFieldValue = result.body.fields[auditField]?.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.
I tried your code and it worked on my side. You just need to select the "Field Type" = "Short Text".
Where exactly you're seeing this error?
And in continuation to the above description, I am using Risk Level (Scripted Field) where I am checking if Risk Score is Low, Medium, High, or Very High as below:
def riskScore = "customfield_AAAAA"
def retval='Low'
def result = get("/rest/api/2/issue/${issue.key}")
.queryString("fields", "customfield_AAAAA")
.header('Content-Type', 'application/json')
.asObject(Map)
def riskScoreValue = result.body.fields["customfield_AAAAA"]
int riskScoreIntValue = riskScoreValue.toInteger()
if (riskScoreIntValue <= 10) {
retval='Low';
}
if (riskScoreIntValue > 30 && riskScoreIntValue < 50){
retval='Medium';
}
if (riskScoreIntValue > 50){
retval='High';
}
return retval.toString();
And Static type checking is occuring in the above code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.