Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need to create a dynamically changing custom field using script runner

FM
Contributor
December 16, 2020

Need help with a Script to return the difference between current date and due date (field of issue )

 

if the value of the difference is 0>diiff<=7 then should return one value 

if the value of the difference is 7>diiff<=14 then should return one value 

if the value of the difference is 14>diiff<=21 then should return one value 

these values supplied should go in one custom field or 3 different field cant decide .

Please help

 

then these dynamically changing Scripted custom field should be reflected in the dashboard showing that an issue is due in one week ,two , three . so as to take action depending on due date .

1 answer

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2020

This is not going to work.

Jira data is is intended to track change.  The data does not change based on time, it changes based on when people (or processes) change it.

"now" is always changing, so a script to recalculate the difference between due and now would have to run over every issue in the system once a second (a second is the smallest time Jira code bothers with, but it's not well used and humans rarely see anything more granular than a minute)

So, there aren't any scripts to do this.

You will need to have a re-think and work out some way to do this without constant recalculations.  As an example, an app that reports on a list of issues could look at the due date, compare it with "now" while it is being rendered and choose to display differently depending on the difference.  That would only run when someone runs the report, so it's not dependent on saving data for issues.

FM
Contributor
December 17, 2020

Maybe i will try to write a schedule job for it and run the script at that particular time of the day so now ()only executes during the schedule time of the job  . The main problem is the script. How do i write the Logic where the script returns the value for three different conditions to three different numeric custom field 

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 17, 2020

You've almost written that code in your question - you can translate your three "if" lines almost straight into code for java or groovy

FM
Contributor
December 21, 2020

the Problem is i am not from the Dev background and that leaves me hanging for some help with the groovy script 

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 21, 2020

When you're new to coding, it can be good to look at what others have done and learn from that.  It's also useful for expert coders too, saves them "re-inventing the wheel".

Ideally simplified stuff, code that tries to do one thing well.  For Scriptrunner, I lean on https://library.adaptavist.com

Suggest an answer

Log in or Sign up to answer