AnsweredAssumed Answered

Setting datetime with JavaScript

Question asked by matjazmuhic on Nov 18, 2010
I have a problem adding datetime property to content. I get current date with javascript and get year,day,month,hour,minute,seconds and miliseconds from it. Then I format it to ISO8601 and set that string to my custom property of type datetime. I also write the date string to the document and it looks like this: 2010-10-18T10:41:44.196Z    which should be okay acording to ISO8601 specifications. All went well till now. But when I check the document in alfresco share the custom property should show this date but instead I get this:  "'>       and that green error box. In logs I found this:   Caused by: java.lang.NumberFormatException: For input string: "Mon ".
I'm a little confused. Because setting the date was fine but getting it again from same property caused problems. And I don't understand how string "Mon " is in date since my date is 2010-10-18T10:41:44.196Z .

This is my script for setting current time and date on document with my aspect "agfo:wfHistory":


var doc = userhome.childByNamePath("checkmeout.txt");
var now = new Date();

var hour = now.getHours();
var min = now.getMinutes();
var sec = now.getSeconds();
var msec = now.getMilliseconds();
var day = now.getDate();
var month = now.getMonth();
var year = now.getFullYear();

if(month.toString().length==1) month = "0"+month;
if(day.toString().length==1) day = "0"+day;
if(hour.toString().length==1) hour = "0"+hour;
if(min.toString().length==1) min = "0"+min;
if(sec.toString().length==1) sec = "0"+sec;
if(msec.toString().length==1) msec = "00"+msec;
if(msec.toString().length==2) msec = "0"+msec;

var date = year+"-"+month+"-"+day+"T"+hour+":"+min+":"+sec+"."+msec+"Z";
doc.content  += date +"\n";

if (doc.hasAspect("agfo:wfHistory"))
{
doc.addAspect("agfo:wfHistory");
}
if(doc.properties["agfo:taskName"] == null)
{
doc.properties["agfo:taskName"] = new Array();
}
if(doc.properties["agfo:taskTimestamp"] == null)
{
doc.properties["agfo:taskTimestamp"] = new Array();
}

var length = 0;

length = doc.properties["agfo:taskName"].length;
doc.properties["agfo:taskName"][length] = "asdf";

length = doc.properties["agfo:taskTimestamp"].length;
doc.properties["agfo:taskTimestamp"][length] = date;

doc.content += "–> "+doc.properties["agfo:taskTimestamp"][length]+"\n\n";

doc.save();

Outcomes