Hi Team,
working on the script for below requirement:
IF (Risk Impact*Risk Probability=0)
Then Risk Level(Calculated) = 0
IF (Risk Impact*Risk Probability<4)
Then Risk Level(Calculated) = 1
IF (Risk Impact*Risk Probability<8)
Then Risk Level(Calculated) = 2
IF (IF(Risk Impact*Risk Probability<9)
Then Risk Level(Calculated ) = 3
Risk level (Calculated) is a scripted field created.
Kindly help me with the script to achieve this as I am new learner to the scripting.
Regards,
Neeta Jain
You have to check both sides of the interval. because for now, everything will be Risk = 3 (you haven't checked lower.
IF (Risk Impact * RiskProbability < 4 AND Risk Impact RiskProbability > 0)
Then Risk Level (Calculated) = 1
For instance, and don't know if I've used AND operator properly,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried below code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
Issue mainIssue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def riskimpact = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_18484".getValue())) as String
def riskoccprobablity = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_18483".getValue())) as String
def risklevel = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_23091".getValue())) as String
if (riskimpact * riskoccprobablity = 0)
{
return 0
}
else if (riskimpact * riskoccprobablity < 4 AND riskimpact * riskoccprobablity > 0 )
{
return 1
}
else if (riskimpact * riskoccprobablity < 8 AND riskimpact * riskoccprobablity >4 )
{
return 2
}
Else if (riskimpact * riskoccprobablity < 9 AND riskimpact * riskoccprobablity > 8 )
{
return 3
}
Kindly check and let me know any correction needed in it.
getting an error :
The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script144.groovy: 16: expecting ')', found '=' @ line 16, column 36. if (riskimpact * riskoccprobablity = 0) ^ 1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The error happens because your question in grammatically unclear - you've got two questions with potentially very different answers in it.
In English, this is one of the examples that absolutely proves the need for punctuations like the Oxford comma and braces. Computers require that preciseness, they cannot infer the existence of them, the way humans can.
In English, your "if" question is stated as "if X times Y equals Z". Grammatically though, there are two answers. You and I can immediately see which one is intended, but a computer cannot because it doesn't speak English or understand the intent.
Your question could be clarified to be
X times (Y equals Z)
Answer: X when Y = Z and 0 when Y != Z
(X times Y) equals Z
Answer: True when ( X * Y ) = Z, otherwise false
So, try the precise grammar of the one you want:
if ( (riskimpact * riskoccprobablity) = 0)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi tried abpove thing, see below:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
Issue mainIssue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def riskimpact = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_18484".getValue())) as String
def riskoccprobablity = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_18483".getValue())) as String
def risklevel = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_23091".getValue())) as String
if ( (riskimpact * riskoccprobablity) = 0)
{
return 0
}
else if ( (riskimpact * riskoccprobablity) < 4)
{
return 1
}
else if ( (riskimpact * riskoccprobablity) < 8)
{
return 2
}
Else if ( (riskimpact * riskoccprobablity) < 9)
{
return 3
}
but still the same error:
The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script59.groovy: 16: expecting ')', found '=' @ line 16, column 39. if ( (riskimpact * riskoccprobablity) = 0) ^ 1 error
Kindly please check syntax of my script, as I am very new learner to it, finding difficulty to resolve it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, that needs an equivalence, not a set operator. try ...y) == 0 )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
== resolve the issue but now other error cames..
Please check my requirement:
I have dropdownlist custom fields for which I need calculation such as:
riskimpact*riskprobablity (both are Dropdown list)
and scripted field is number value.
so can you please let me know how do I declare them, as i am getting an error at the declaration itself.
thanks in advance
Regards,
Neeta Jain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You'll need to map the stored options in the drop-downs on to numerics.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i have made the changes to the field at the declation:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
Issue mainIssue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def riskimpact = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_18484".getValue())) as Integer
def riskoccprobablity = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_18483".getValue())) as Integer
def risklevel = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_23091".getValue())) as Integer
if ( ( riskimpact * riskoccprobablity) == 0)
{
return risklevel == 0
}
else if ( ( riskimpact * riskoccprobablity) < 4)
{
return risklevel == 1
}
else if ( ( riskimpact * riskoccprobablity) < 8 )
{
return risklevel == 2
}
else
{
return risklevel == 3
}
But getting error at the declarion:
Can not find matching methiod: java.lang.String#GetValue()please check if the declared type is correct.
Kindly suggest
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You say the fields you are reading are select-lists. The fields will contain "options" which you can't just cast to an integer because they are a complex object. Imagine a list of animal species - you can't just say "what number is an elephant?"
You could try to get the name of the option as a string, and use parseInt oon it, but the safer way to do this (in case one of your admins renames or adds an option that it won't work for) is with an if or case statement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.