I need to realize the calculation of the following fields through scriptrunner
issues has 5 fields
Single choice field A (2023, 2024...).
Single choice field B (office a, office b...).
Numeric field C (total amount for office a, total amount for office b...).
Numeric field D (Amount).
Numeric field E (office a remaining amount, office b remaining amount).
i need to choose
Single choice field A (2023) + Single choice field B (office a, office b...)
The value of field B is automatically obtained (the total amount of office a, the total amount of office b...).
Fill in field C (amount) every time you create a new issue
Total amount of office a - amount (all issues associated with office a) = remaining amount of office a.
Restrictions: remaining amount <0, no issues are allowed
I don't know if the description is clear, please help me solve this problem.Thanks!
I need to run in 2 projects
Hi @jack
I have a doubt to clarify, i.e. in your description, you mentioned:-
The value of field B is automatically obtained (the total amount of office a, the total amount of office b...).
I assume this is for Numeric Field C; how do you get the updated value for each year? Is it via DB Query or a REST server, or is it expected to be updated by the Behaviour, i.e. hard coded?
Kindly clarify so I can provide a better example.
Thank you and Kind regards,
Ram
Hi @jack
Below is an example code for your reference:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def issue = issue as MutableIssue
def customFieldManager = ComponentAccessor.customFieldManager
def totalAllocation = customFieldManager.getCustomFieldObjectsByName('Total Allocation').first()
def totalAllocationValue = issue.getCustomFieldValue(totalAllocation) as Double
def amountUsed = customFieldManager.getCustomFieldObjectsByName('Amount Used').first()
def amountUsedValue = issue.getCustomFieldValue(amountUsed) as Double
if (totalAllocationValue && amountUsedValue) {
(totalAllocationValue - amountUsedValue) as Double
}
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
So this code, basically does a simple subtraction of the Total Allocatoin Value with the Amount Used and will return the Remaining Amount.
Just another doubt to clarify, if let say you do a calculation on one issue for one office, e.g. Office A. And if you create another issue for Office A, are you expecting that the total value remaining is passed on to second issue?
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ thank you for your reply.
yes, expecting that the total value remaining is passed on to second issue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @jack
Thanks for the clarifications.
If this is the approach you want to take, I'm sorry, but it will not work as expected.
It is a very complex approach. Why? Because the value of the field is not stored anywhere, and if you try to pass it from one issue to another, it will not work as expected.
Unless you want to create a table in the database to store these values so you can query them.
It may be possible (no assurance) if you create an epic and store its value. So every time a new issue is created and added to the epic, the epic can do the calculation, and the latest value from the epic can be passed to the new issue.
I am looking forward to your feedback.
Thank you and Kind regards,
Ram
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.