Hi there ,
I am looking for some possible solutions to this . I need a scripted field which displays the days between the current date and another existing custom date field on the issue. The issue I’m having is trying to figure if there is a way to auto refresh so that this scripted field will update with the new value daily ? I can’t seem to find any defined solution to this . It seems the value is only updated when a user opens up the issue triggerering a reindex of the issue and the new value is displayed . This won’t work for me here as I need the values displayed on a dashboard where users may not have opened the issue but the scripted field needs to show the accurate days remaining . Hoping for some solutions here
thanks
What do you intend to use to trigger the update?
If you want it to trigger automatically, you could use a Job, i.e., an Escalation Service or a Scheduled Job, to update the date and the beginning of every date, which will refresh the date field's value.
Also, a Scripted Field may not be applicable if you intend to use the Job approach.
Kindly clarify this so I can try to provide an example.
Thank you and Kind regards,
Ram
Hi Ram, I am open to suggestions there as well in terms of what to use to update I was planning on running a scheduled job every morning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You will first need the Server-Side Behaviour and the Escalation Service for your case.
The Server-Side Behaviour is required to replace the Scripted Field, i.e., to calculate on the Create / Edit screen.
You will need to create 2 Server-Side Behaviour codes, i.e. both the date fields separately, as shown in sample working codes below:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def date1 = getFieldById(fieldChanged)
def date1Value = date1.value as Date
def date2 = getFieldByName('Date2')
def date2Value = date2.value as Date
def sampleNumber = getFieldByName('Sample Number')
def remainderDays = (date2Value - date1Value) as Integer
sampleNumber.setFormValue(remainderDays)
and
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def date1 = getFieldByName('Date1')
def date1Value = date1.value as Date
def date2 = getFieldById(fieldChanged)
def date2Value = date2.value as Date
def sampleNumber = getFieldByName('Sample Number')
def remainderDays = (date2Value - date1Value) as Integer
sampleNumber.setFormValue(remainderDays)
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Behaviour configuration for the 1st Date field:-
and below is a screenshot of the Server-Side Behaviour configuration for the 2nd Date field.
Both these Server-Side Behaviour configurations are required to trigger the remainder date calculation if any of the Date fields' values are updated.
Next, once the issue has already been created, you will need to use the Escalation Service to trigger the Date field update and calculation every 24 hours.
Below is a sample working code for the Escalation Service for your reference:-
import java.text.SimpleDateFormat
def dateFormat = 'yyyy-MM-dd hh:mm:ss.SSS'
def sampleDateFormat = new SimpleDateFormat('d/MMM/yy')
def date = Date.parse(dateFormat, issue.getCustomFieldValue('Date1').toString())
def calendar = Calendar.instance
calendar.setTime(date)
calendar.add(Calendar.DATE, 1)
def sampleNumberValue = issue.getCustomFieldValue('Sample Number') as Integer
issue.update {
setCustomFieldValue('Date1', sampleDateFormat.format(calendar.time) as String)
setCustomFieldValue('Sample Number', (sampleNumberValue - 1) as String )
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Escalation Service configuration:-
Whenever the Escalation Service is triggered, it will update the date value set for the Date 1 field which will cause the number of days in the number field to reduce by 1 on every execution. This will implicitly update the value of the Gadget.
I hope this helps to solve your question. :-)
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.
Has your question been answered?
If yes please accept the answer provided.
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,
I Tried this one, could you please post the output how it looks
Thanks
Anusha
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.
Hi Caoimhin,
I can confirm that scripted fields cannot be triggered to update daily, but using ScriptRunner, you could use a Schedule to update a custom field with a calculated value at a defined interval.
This means the field could be updated daily, such as 6 am, to ensure the value is always up-to-date in dashboards.
I have included links below to the documentation for the Scheduled Jobs feature on both the Server/Data centre and Cloud versions of ScriptRunner.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kristian,
when you say update a custom domain, could you expand on that on how I could achieve this on say a custom scripted field called “x”.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Caimhin,
My apologies; I meant to say Custom Field, and I made a typing error in my previous response, which I have now corrected.
You could not achieve this on a scripted field due to how scripted fields work, instead, you would have to update a regular custom field daily with a script to achieve your requirement.
Regards,
Kristian
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.