BG

Hey guys,

so what I want to do: In the end I want to have a dashboard that displays the average model age in days.

My idea was to have a report that generates a table column which gives me the model age in days. In Excel this would be fairly easy, you just have to go: Current Date - ReleasedOnDate = done

But I'm kind of stuck how to accomplish this via automated report since currentDate - ReleasedOnDate doesn't work this way, I can only compare those to each other...

 

Thanks in advance

Bartosz

by Kay Fischbach
Posted on Thu, 09/19/2019 - 09:30

That's an interesting task. There are two things you need. A way to get the date in a comparable format (preferably not String - I know it's possible with string, by splitting the string and doing some unnecessary things, but just don't use String) and a way to actually do the comparison.

Luckily only the first thing is something you need ARIS knowledge for that comes with using ARIS Scripting for a while.

(Note: For the following I'll assume with model age you mean time between date of last change and current date. If you mean time between date of model creation and current date, replace AT_LAST_CHNG_2 with AT_CREAT_TIME_STMP)

The report script help tells you that when you use someModel.Attribute(Constants.AT_LAST_CHNG_2, yourLocale) you'll get a JavaScript object of the class "Attr". This is not entirely true. What you actually get is an instance of a child class of "Attr", called "AttrTime... " uh, I'm not really sure, either "AttrTimeDef" or "AttrTimeStampDef" (probably the latter) - it doesn't matter anyway, because both classes have the method we need. This method is known as "MeasureValue()". This method returns an a Java object of the class java.util.Date. Yeah Java. Not JavaScript. This is important for how you'll proceed.

As you can imagine, you're most definitely not the first person that wants to compare two Java dates. A quick search with the search engine of your choice would probably bring you to a Stackoverflow thread and you'll find an answer like the following

https://stackoverflow.com/a/20165708

That's just perfect. Putting aside that we don't have strings for our dates, this does exactly what we want.

For the second date which we need for comparison one simply has to know that "new java.util.Date()" creates a Java Date instance with a timestamp of right now (down to the millisecond). Somewhat easy to know for people that worked with Java before starting with JavaScript and ArisScript, hard to know for people that got into programming with JavaScript and ArisScript.

Well now you've got two dates and a method how to compare them, cobble everything together and you'll get something like this:

(Script context: Models; everything output related doesn't matter; it doesn't need permission to write to database; it does need permission to open dialogs)

 

var nLocale = Context.getSelectedLanguage();
var selModels = ArisData.getSelectedModels();

for each(var selModel in selModels){
    var lastChangeDate = selModel.Attribute(Constants.AT_LAST_CHNG_2, nLocale).MeasureValue();
    var dateNow = new java.util.Date();
    var diff = dateNow.getTime() - lastChangeDate.getTime();
    
    var differenceDays = java.util.concurrent.TimeUnit.DAYS.convert(diff, java.util.concurrent.TimeUnit.MILLISECONDS);
    
    
    Dialogs.MsgBox(differenceDays);
    
    
}

Neat. Note that obviously because we used this solution, it comes with all the up- and downsides of this solution, about which you can read in the Stackoverflow comments. Notably this solution apparently does account for leap years, but you loose precision by converting the milliseconds to days with the given method. There is also an alternative solution for calculating the diff variable in the Stackoverflow comments, if you need a more precise result.

That we assign our Java objects to JavaScript variables shouldn't really suprise anyone, after all while we do work with Java objects, this is still JavaScript we're working with.

0
by Bartosz Golis Author
Posted on Tue, 09/24/2019 - 15:07

In reply to by Kay Fischbach

Hi Kay,

thanks a lot for your extensive reply (and sorry it took me so long) the key was to use Java and not Java Script in my case. So thanks again.

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock