Forums

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

Not able to calculate the Scripted field value

Avinash Gautam
Contributor
December 2, 2016

Hi Nic Brough [Adaptavist],

 

I wanted to create a scripted field for calculating two field values

 

First field  Severity Of Impact(drop down) : Very high, High, Medium, Low, Very Low     //customfield_14531

Second field Probability Of Occurence(drop down) : 10, 20, 30 .. 100                           //customfield_14532

 

Required Scripted field is  Calculated field = Severity Of Impact * Probablity of occurance

 

I have tried the below script but it's not working

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_14531")
def cField1 = customFieldManager.getCustomFieldObject("customfield_14532")
def soi = issue.getCustomFieldValue(cField)
def poc = issue.getCustomFieldValue(cField1)

if (soi == "Very Low")
return "Exposure = " + 1*poc / 100 + "%" ;
else if (soi == "Low")
return "Exposure = " + 2*poc / 100 + "%" ;
else if (soi == "Medium")
return "Exposure = " + 3*poc / 100 + "%" ;
else if (soi == "High")
return "Exposure = " + 4*poc / 100 + "%" ;
else
return "Exposure = " + 5*poc / 100 + "%" ;

 

 

The above script is throwing error and not working. Please help to solve this. Thanks!

1 answer

1 accepted

0 votes
Answer accepted
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 Champions.
March 25, 2014

Not really, this is correct behaviour. You've got a rule that says "people have to be in group X to see this issue", so when someone outside the group is assigned the issue, they can't see it. You need to grant the assignee the right level of security for that issue.

Tobias Exner
March 25, 2014

But shouldn t than JIRA check on assigning if security levels fit? I don t see a reason for assigning an issue to somenone who won t be able to process or even see it. This leads into "dead-ends" in the process, especially because the person that assigns an issues to soemone else doesn t necessarily know if the desired person really has a corresponding permission.

And I assume it would be cheap/simple to check if desired assignee has the corresponding security level. So JIRA could permit or at least warn the user.

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 Champions.
March 25, 2014

Definitely would be a good check to have, but I don't think it's always right for everyone to enforce it.

I've not noticed a feature request for it though. My searching on jira.atlassian.comhas failed me again.

I once implemented a custom field for a client that was really simple - if you assigned an issue to someone who didn't have access, it put a huge red box on-screen saying "assigned user can't see this". I suspect you might be able to do this with a script-runner scripted field. It is a bit after-the-fact though.

I did have a better fix in an older version - another derived field, done in a plugin - it was a "multi user" type field, but it derived the contents from "can see this security level" and "assignable user". Then we used it in the "assignable user" permission, so the list was chopped down to just those who could see it. (Yes it looks recursive, we had to code with that in mind)

Suggest an answer

Log in or Sign up to answer