Hi Friends,
Hope you all are safe and in good health
I have one query, user is asking for calculation field,
would it be possible to add field to JIRA, containing formula/live calculation?
I have 2 number field Revenue and Time, user want to divide Revenue by Time and put the output in another field name "Profit". Is it possible, please help.
@Stephen_Wright @Nic_Brough__Adaptavist_ @Kristian Walker (Adaptavist) @Adrian_Stephen @Derek_Fields @Ravi_Sagar__Adaptavist_
@Martin Bayer [MoroSystems, s.r.o.]
Thanks
Vikrant Yadav
A bit more advanced than you need, but you can just drop the bit about following links - https://library.adaptavist.com/entity/calculate-the-sum-of-all-values-of-a-custom-field-in-linked-issues
Vikrant, the documentation posted by @Nic Brough -Adaptavist- should be enough, but if you're not programmer, here is a code you should use (I didn't test it so if there are any exceptions, let me know)
NOTE: do not forget to fill in revenueCFId and timeCFId properties with real custom field IDs
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.customFieldManager
def revenueCFId = 111
def timeCFId = 222
def revenueCF = customFieldManager.getCustomFieldObject(revenueCFId)
if (!revenueCF) {
log.debug ("Custom field with ID " + revenueCFId + " not found")
return null
}
def timeCF = customFieldManager.getCustomFieldObject(timeCFId)
if (!timeCF) {
log.debug ("Custom field with ID " + timeCFId + " not found")
return null
}
def revenue = issue.getCustomFieldValue(revenueCF)
def time = issue.getCustomFieldValue(timeCF)
return revenue/time
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nic Brough -Adaptavist- @Martin Bayer [MoroSystems, s.r.o.] Thanks you guys for the help. Script is working fine. Providing accurate result.
Thanks a lot :) ..you are the experts.
Now user is asking to provide result in profit per hour, is it possible to calculate/convert time in hour ? Time field doesn't exists, day and time field is available only. Please suggest if there any solution of this.
Thanks Again!
Stay Safe!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you have a date or date/time field, you're going to need to come up with a rule to convert it into a length of time
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nic Brough -Adaptavist- @Martin Bayer [MoroSystems, s.r.o.] is there any way to convert or calculate issue created date and resolved date into hours.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nic Brough -Adaptavist- how can i convert it into length of time ? Please suggest, is adaptivist library having any script related to this thing ?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nic Brough -Adaptavist- @Martin Bayer [MoroSystems, s.r.o.] i want divide Revenue ( number field) by Logged Time field and put value in Profit. Please suggest
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, you can get logged time in seconds (I hope I remember unit correctly, but you can test it):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def worklogManager = ComponentAccessor.worklogManager
def customFieldManager = ComponentAccessor.customFieldManager
def revenueCFId = 111
def revenueCF = customFieldManager.getCustomFieldObject(revenueCFId)
if (!revenueCF) {
log.debug ("Custom field with ID " + revenueCFId + " not found")
return null
}
def revenue = issue.getCustomFieldValue(revenueCF)
def worklogSeconds = worklogManager.getByIssue(issue)*.getTimeSpent().sum()
return revenue/worklogSeconds
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Martin Bayer _MoroSystems_ s_r_o__
I am new to Jira, I always wonder where to write this code exactly.
Could you please help me understand where exactly I have to write this script to obtain the result.
Thanks,
Sangmesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sangmesh , welcome on the community. Could you create new thread with Topic you want to discuss? You can mention me, so I receive notification.
This topic is about calulations with custom fields values, so let's keep it clean :) thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.