Forums

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

Script need to be modified

neeta jain
October 9, 2020

Hi Team,

I have implemented a script to calculate Number if weeks from start date to end date, see below:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*
import static java.lang.Math.*
import java.sql.Timestamp

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_18880');

def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_12110');

if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {
def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date

def diffdate = dateValue - dateValue2
double noofweeks = diffdate/7

double roundNoOfWeeks = Math.round(noofweeks)

int value = (int) roundNoOfWeeks;

return value

}

 

Now I need some modification in it, 

So the current calculation is (Today - Start date), then once reach the End date, the calculation will be (End date - Start date).

So need Number of weeks =  Today's date(system date) -Start Date

and 

If one issue reached to end date then Number of weeks = End Date-Start date.

 

Kindly please help me to modify this, I am not aware how to get the system date in the script.

 

Regards,

Neeta Jain

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Kristian Walker _Adaptavist_
Community Champion
December 14, 2020

Hi John,

Thank you for your question.

I can confirm that if you are using ScriptRunner for Jira Cloud then we do not provide the aggregrateExpression() search method as this is currently only available in the Server version of ScriptRunner.

As for the server version, I can confirm this output can only be displayed in the query and cannot be displayed in dashboard gadgets as it is calculated when the JQL search is run.

If you have further questions around the server version then I would ask you to raise a support ticket with our server support team here so that a member of this could advise if there is another way to achieve your requirement. 

I hope this helps.

Kristian

Hannes Kockro
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 30, 2021

Hi Kristian,

do you know if it is possible to show the aggregateExpression() results on a confluence page?

 

Best 

Hannes

TAGS
AUG Leaders

Atlassian Community Events