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
Alexey Matveev Community Champion Jan 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

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 Community Champion Jan 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

Worked like a charm, thanks a lot! 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

92 views 0 1
Join discussion

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