Hi,
I have a requirement to create a new field to calculate ageing. I have below fields created,
Custom date field A
Scripted field B
Custom date field C
When Custom Date field A has a value, Scripted field B should start calculating the number of dates (that is A - System date) until Custom date field C gets a value
We have Script runner for JIRA plugin. Could you please help me in getting the script for this
After going through your description and comment, what you are trying to do will not work 100% as you expect when using the Scripted Field, i.e. for the Ageing field.
For instance, if you want the auto calculation of the Scripted Field to take place, this is doable with:-
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def sampleDate = customFieldManager.getCustomFieldObjectsByName('Sample Date').first()
def sampleDateValue = issue.getCustomFieldValue(sampleDate) as Date
def currentDate = new Date(System.currentTimeMillis())
(sampleDateValue - currentDate) as Long
However, suppose you intend the Scripted Field to stop the calculation when the Actual Date is added. In that case, this will not work as you expect, i.e. even if the Actual Date is added, the Scripted Field will continue the calculation resulting in Negative Values.
You could add a condition something like:
if (!actualDateValue) {
(sampleDateValue - currentDate) as Long
}
Which will remove the value from the Scripted Field if the Actual Date is added.
If you intend to preserve the value from the Scripted Field, you could pass the Scripted Field value to another text field once the Actual Date field's value is added.
Below is the complete sample script for your reference:-
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def sampleDate = customFieldManager.getCustomFieldObjectsByName('Sample Date').first()
def sampleDateValue = issue.getCustomFieldValue(sampleDate) as Date
def actualDate = customFieldManager.getCustomFieldObjectsByName('Actual Date').first()
def actualDateValue = issue.getCustomFieldValue(actualDate)
def currentDate = new Date(System.currentTimeMillis())
if (!actualDateValue) {
(sampleDateValue - currentDate) as Long
}
Please note that the sample script provided is not 100% exact to your environment. Hence, you will need to make the required modifications.
I hope this helps to answer your question. :)
Thank you and Kind regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_
It worked for my first scenario :)
Could you please help in below,
Once there is actualDatevalue, the calculation should stop and return the existing value even if it 1 or 2 or whatever it is
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
However, suppose you intend the Scripted Field to stop the calculation when the Actual Date is added. In that case, this will not work as you expect, i.e. even if the Actual Date is added, the Scripted Field will continue the calculation resulting in Negative Values.
You need to find a way to store the value before the field value is updated. For example, store it in a dummy table, invoke it again from the table, and display the result in the Scripted Field.
Even if you try to pass the value to a List, the List will reset when the Actual Date field value is set.
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.
Scripted field will calculate the value everyday once the custom date field A is selected?
What is expected once the custom date field C is populated?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Example:
I have a planned date field and Ageing field. Requirement is, if the planned date is today, then the document should be reviewed within 5 days.
So once the planned date is selected, then the Ageing field should calculate the number of days like Planned date - System date. It should get updated everyday.
Once the Actual date field gets value, then the counter of Ageing field should stop. Our clients will pull the Ageing column and make a report of issues which are more than 5 days.
Here Ageing field is my scripted field. Please let me know if you need more information
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.
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.