Getting Date Info From Nolio "Execute Javascript code" resulting in undefined
search cancel

Getting Date Info From Nolio "Execute Javascript code" resulting in undefined

book

Article ID: 219801

calendar_today

Updated On:

Products

CA Release Automation - Release Operations Center (Nolio)

Issue/Introduction

We're using the "Execute Javascript code" to capture date/time information and it is returning output similar to: undefined-2021-07-16-undefined 10:44:12

While using the following javascript code:

var d = new Date();
var minutesToAdd=0;
var futureDate = new Date(d.getTime() + minutesToAdd*60000);
var localtime = futureDate.toLocaleTimeString('en-US', { hour12: false});
var newDate = new Date();
var myTime = new Date(newDate.getTime());
var myMMDDYYY = myTime.toLocaleDateString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit' });
var chunks = myMMDDYYY.split("/");
var theDateFormatted = chunks[1]+'-'+chunks[2]+'-'+chunks[0];
output1 = theDateFormatted + ' ' + localtime;

 

 

Environment

Release : 6.7

Component : CA RELEASE AUTOMATION ACTION PACK

 

Cause

The problem is in the "chunks" statement because there are no forward slashes in the myMMDDYYY variable. 

 

Resolution

Dates and timestamps are frequently used in various places. The "Execute Javascript code" is frequently used to get date information because the data can be manipulated as desired. To fix the problem for this issue, change the line: var chunks = myMMDDYYY.split("/");
to: var chunks = myMMDDYYY.split("-");

However, something else to consider... there is a "Get Current Date and Time" action that will offer output fields for:

  • date (default input dateFormat uses yyyy-MM-dd);
  • time (default input timeFormat uses HH:mm:ss); and
  • Time in Millis (which is basically equal to the epoch timestamp you can get in Unix/Linux - given in the format: NNNNNNNNNNNNN. Can get date/time value using the command: date -d @NNNNNNNNNN,NNN +%Y-%m-%d\ %H:%M:%S,%s%N).