A script to divide values of two fields

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
Accepted answer

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

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

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

Worked like a charm, thanks a lot! 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,950 views 19 22
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you