Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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.
https://gist.github.com/gfrison/812501

"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

ref: http://groovycookbook.org/basic_types/dates_times/"



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')
if(lifeCycleDays){
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
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

321 views 2 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you