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 votes
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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,796 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot