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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

145 views 1 17
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