Script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.plugin.osgi.container.OsgiContainerManager
import com.atlassian.jira.user.ApplicationUser
def A = getCustomFieldValue("Luck")
def B = getCustomFieldValue("Tempo Hours")
def C = A-B
Return C
...........
I am getting static type error at "-".
Could someone please help me on how to create the calculated field which can substarct A from B
Hello @Yatam_ Annapurna
It is static type checking, you can ignore that.
Static type checking occurs because getCustomFieldValue returns Object type value and do not know what type exactly it is. But when code will run and if Luck field have same type as Tempo Hours, everything will work because groovy is dynamic language
Thank you Mark for your quick answer.
Below is the full description of the issue:
I have one custom field (Number) - "Luck", to input the total hours estimated for 2018
I have created a script field to capture the Total time spent on an issue and that is "Tempo Hours".
As you said, we cant do this arithmetic operation between two different types of fields, I have converted the number field "Luck" to Script field "Total Hrs - 2018".
Now both are script fields. Below is the script. I have taken "Number Template" while creating script filed.
Total Hrs - 2018:
import com.atlassian.jira.component.ComponentAccessor
def A = getCustomFieldValue("Luck")
return A
Tempo Hours:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.util.AggregateTimeTrackingCalculator;
import com.atlassian.jira.issue.util.AggregateTimeTrackingCalculatorFactory;
AggregateTimeTrackingCalculatorFactory timeTrackingCalculatorFactory = ComponentAccessor.getComponentOfType(AggregateTimeTrackingCalculatorFactory.class);
AggregateTimeTrackingCalculator calculator = timeTrackingCalculatorFactory.getCalculator(issue);
return calculator.getAggregates(issue).getTimeSpent()/3600;
Bothe are returning correct values
Now, I need to get the difference between Total Hrs - 2018 ad Tempo Hours
So, I have used the below code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.plugin.osgi.container.OsgiContainerManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import java.lang.*
import java.util.*
import java.io.*
import java.net.*
import groovy.lang.*
import groovy.util.*
import java.math.BigInteger
import java.math.BigDecimal
def A = getCustomFieldValue("Total Hrs - 2018")
def B = getCustomFieldValue("Tempo Hours");
def C;
if(B!=null)
{
C= A-B
}
return C;
Result:
Its is always returning the A value.
For example: If A=100 and B=60
C=A-B, then I am expecting 40 but getting 100,
If I change this to C=B-A, then I am getting 60.
So, basically it is not doing any calculation, simply taking the value before the minus and assigning to C.
I am so tired of googling for this. Kindly help me on this. I will be so thankful to you.
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.