Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Insight Groovyscript Date Calculation

This is more of an inquiry --can this be possible-- and so I don't expect a solution, but would like to know if I'm wasting my efforts.

I am very new to groovyscript-- very new to scripting in general. However, we utilize Mindville Insight with our Jira Database and a customer has requested the capability to add a date from an attribute field of an object to a number (given in days/years) from another attribute field and update a 3rd attribute field with the new date.

The goal is to track life cycles for equipment, etc. 
(Equipment A was fielded on 1 JAN 21 -- has a life cycle of 3 years --  End of Life will be 1 JAN 24)

The customer also wants the End of Life date to update if the life cycle is changed (in case they find a given equipment only lasts 2 years with heavy use, etc.

I'm assuming this would run via Insight automation once the object is created/edited.
As a bonus harder question, the customer wants to know if this script could call an attribute from a different object in this script... for example. Model A has a life cycle of 3 years, Equipments B, C, D are the same Model A, but have different fielded date attributes-- the End of Life field for each would pull that life cycle field from the model object. (And again, if the life cycle field is updated, then the end of life field on each item would update accordingly...

I've found this code for adding dates and a number, but am unsure how to "call" the attribute fields.

"Groovy also has a Time Category class which gives you DSL style syntax for manipulating dates. Here is an example:

import org.codehaus.groovy.runtime.TimeCategory
now = new Date()
println now
use(TimeCategory) {
footballPractice = now + 1.week - 4.days + 2.hours - 3.seconds
println footballPractice
which will produce output like this:

Sat Sep 27 10:00:12 EST 2008
Tue Sep 30 12:00:09 EST 2008


Thank you for any insight (pun intended) and help in this matter.
If you know of any previous help requests that reflect my query, please let me know, as I haven't had much luck finding a similar question for Insight Groovy scripts, just groovyscripts or jira service desk scripts.

1 answer

0 votes

The short answer is generally... if you can think of it and you can identify all the decision points, you can probably do it using a script.

Using the utility class I shared in this article ... you could write a script like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.util.JiraHome
def jiraHome = ComponentAccessor.getComponentOfType(JiraHome.class).home
Class InsightUtils = new GroovyClassLoader(getClass().getClassLoader()).parseClass(new File("$jiraHome/path/to/scripts/InsightUtils.groovy"))

//object is already defined when running from insight automation with object created/object updated events
//This assumes the equipment object has a "Model" attribute that is a reference to another object type that has "Life Cycle Days" attribute with a number of days
def lifeCycleDays = InsighUtils.getObjectAttributeFromDotNotation(object, 'Model.Life Cycle Days')
//if your model object has n years as lifecycle, we'd have to do it like this:
def lifeCycleYears = InsighUtils.getObjectAttributeFromDotNotation(object, 'Model.Life Cycle Years')
def endOfLifeDate
def dateAttributeValue = InsightUtils.getObjectAttributeFromDotNotation(object, 'Some Date Attribute')
endOfLifeDate = use(TimeCategory) { dateAttributeValue + lifeCycleDays.days }
} else if(lifeCycleYears) {
endOfLifeDate = use(TimeCategory) { dateAttributeValue + lifeCycleYears.years }

InsighUtils.setObjectAttribute(object, 'End of Life Date', endOfLifeDate)

Now, this just shows the high-level logic ... you'd have to either install the InsightUtils class somewhere in your jira home directory or go extract the code you need from it. The real magic is in "getObjectAttributeFromDotNotation" and "setObjectAttribute" methods. 

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events