A script to divide values of two fields

admin_tt January 25, 2018

Greetings! 

I'm pretty new to this whole Scriptrunner thing, so I'm looking for some help with a scripted field. I'm looking for a script, which would allow me to divide a variable value on a static one and show a result as a percentage. 
I'm going to use two custom fields for a variable value and a result of this equation. 

Something like this: 
N (variable) / 40 = Z% 


1 answer

1 accepted

1 vote
Answer accepted
Alexey Matveev
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 Leaders.
January 25, 2018

What do you mean that you will use two custom fields for a variable value? one value can be used for one field or there is something else?

Basically your script would look like this

import com.atlassian.jira.component.ComponentAccessor

def cs = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("customfieldname");
return issue.getCustomFieldValue(cs)/150
admin_tt January 26, 2018

Morning! 
Well, I'm talking about configuring two separate fields: a field for user's value and a field to show a result. 
Right now, with your script (thanks for that!), it looks like this: 
http://prntscr.com/i5sb9n
The result, I'm looking for: 
http://prntscr.com/i5se8j

Alexey Matveev
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 Leaders.
January 26, 2018

Then you need to create a scripted field with a script like this

import com.atlassian.jira.component.ComponentAccessor

def cs = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("customfieldname");
return issue.getCustomFieldValue(cs)/40*100
admin_tt January 26, 2018

Worked like a charm, thanks a lot! 

Suggest an answer

Log in or Sign up to answer