Hexagon Geospatial
MENU

M.App Enterprise Tutorials

Not sure on how to get started or looking for a workflow to get M.App Enterprise up and running. Tutorials provide step by instruction on some of the most common configurations and workflows to get M.App Enterprise configured up and running quickly.
Showing results for 
Search instead for 
Do you mean 

How to use JavaScript to parse specific datetime info as a Functional Attribute in Analyzer View

by sclow ‎03-19-2018 07:41 AM - edited ‎03-19-2018 07:42 AM (274 Views)

Question

Analyzer Views use datetime fields to visualize and chart incidents by a datetime field in the specified dataset. How can the datetime field be further parsed as a functional attribute to obtain and eventually chart more specific information about the datetime value of each record?

Answer

Given that a datetime field can be parsed of all the different parts that make it up there are a range of possibilities to answer this question.

Below is an example of using JavaScript to create a functional attribute against Incident data in an Analyzer View that contains datetime. Please pay attention to the comments within.

 

// create Date object from valid string inputs
var datetime = new Date(currentRecord["EVT_DATE"]);

// format the output
var year = datetime.getFullYear();

var month = new Array();
 month[0] = "January";
 month[1] = "February";
 month[2] = "March";
 month[3] = "April";
 month[4] = "May";
 month[5] = "June";
 month[6] = "July";
 month[7] = "August";
 month[8] = "September";
 month[9] = "October";
 month[10] = "November";
 month[11] = "December";
var mon = month[datetime.getMonth()]; 
    
var day = datetime.getDate();


var hour = datetime.getHours();
if (hour < 10)
    hour = "0"+hour;

var min = datetime.getMinutes();
if (min < 10)
    min = "0"+min;

var sec = datetime.getSeconds();



// put it all together depending on the output you wish to recieve
// These are just examples and not all of the possibilities
// Uncomment to use
//var dateTimeString = hour+':'+min+ ':'+sec; //If wanting H:M:S
//var dateTimeString = year; //If wanting YYYY
//var dateTimeString = mon+' ' +day+', '+year; //If wanting Month DD, YYYY

    

return dateTimeString;

See result when creating new Functional Attribute 'CalcTime'

 

result.PNG

Overview
Contributors