Hello,<br><br>I've been trying to write a simple JS script, which is called from within the XML dialplan, in order to convert the value of ${created_time} to something more meaningful than UNIX time in ms. The problem is when I try to print something to the console (see log application below), I get NaN (not a number) for variable ${created_date}, even though I don't want a number (a string is fine, I tried enforcing this with toString()). Moreover, you'll notice I've left out var month = date.getMonth();, because if I don't I get the following error: TypeError: date.getMonth is not a function. I can't figure out why, it's documented in JS in the date object, and the syntax is identical to other functions I use to acquire object values. Any hints would be greatly appreciated, I've been trying different code variations for over two hours now and I'm stuck. Thanks.<br>
<br>Here's the call in the dialplan:<br><br><action application="javascript" data="unixtocal.js $created_time"/><br><br>And here's the JS script itself:<br><br>var date = new Date(argv);<br>
var hours = date.getHours();<br>hours = hours.toString();<br>var minutes = date.getMinutes();<br>minutes = minutes.toString();<br>var seconds = date.getSeconds();<br>seconds = seconds.toString();<br>var ms = date.getMilliseconds();<br>
ms = ms.toString();<br>var year = date.getFullYear();<br>year = year.toString();<br>var day = date.getDate();<br>day = day.toString();<br><br>session.execute("set", "created_year="+year);<br>session.execute("set", "created_date="+day);<br>
session.execute("set", "created_hours="+hours);<br>session.execute("set", "created_minutes="+minutes);<br>session.execute("set", "created_seconds="+seconds);<br>
session.execute("set", "created_ms="+ms);<br><br>Then the dialplan takes over again, for example:<br><br><action application="log" data="INFO Date is ${created_date}"/><br>