Can anybody tell me how this normal expression is done in javascript
so it returns a date in the format '12345 00:00:00'Code:$negdatestamp='01/01/2200 01:00:00' - tod()
Can anybody tell me how this normal expression is done in javascript
so it returns a date in the format '12345 00:00:00'Code:$negdatestamp='01/01/2200 01:00:00' - tod()
Ok I finally found a way to do this. Its a bit clumsy but works.
Here is the full script that add a custom activity record to any activity file
ThisCode:// This script add a custom activity record. // function addActivity(record, activitytype, activitytext) { var strFileName =system.functions.filename( record ); var strRecordID; var strActivityFilename; strRecordID = record.number ; switch (strFileName) { case "probsummary": strRecordID = record.number ; strActivityFilename ="activity"; break; case "cm3r": strRecordID = record.number ; strActivityFilename ="activitychanges"; break; case "incidents": strRecordID = record.incident_id ; strActivityFilename ="activityservicemgt"; break; case "rootcause": strRecordID = record.id ; strActivityFilename ="activityproblem"; break; case "knownerror": strRecordID = record.id ; strActivityFilename ="activityknownerror"; break; default: break; } var activityFile =new SCFile(strActivityFilename); var strSqlActivity; var arrDescription =new Array(); var now =new Date(); var future =new Date(2200,1,1,1); var delta = future -now - (30*86400000); var days =String(parseInt(delta/86400000)); var hours =String(parseInt((delta - (days*86400000))/3600000)); var minutes =String(parseInt((delta - (days*86400000) - (hours*3600000))/60000)); var seconds =String(parseInt((delta - (days*86400000) - (hours*3600000) - (minutes*60000) )/1000)); var negdatestamp =new XMLDate( "P"+days+"DT"+hours+"H"+minutes+"M"+seconds+"S"); activityFile.number = strRecordID; activityFile.type = activitytype; activityFile.operator =system.functions.operator(); activityFile.datestamp = now; activityFile.negdatestamp =negdatestamp.getDatum(); arrDescription[0]= activitytext; activityFile.description = arrDescription; activityFile.doInsert(); }
and thisCode:var now =newDate(); var future =newDate(2200,1,1,1); var delta = future -now - (30*86400000); var days =String(parseInt(delta/86400000)); var hours =String(parseInt((delta - (days*86400000))/3600000)); var minutes =String(parseInt((delta - (days*86400000) - (hours*3600000))/60000)); var seconds =String(parseInt((delta - (days*86400000) - (hours*3600000) - (minutes*60000) )/1000)); var negdatestamp =newXMLDate( "P"+days+"DT"+hours+"H"+minutes+"M"+seconds+"S");
is the code that replaces that simple rad expression from first post.Code:activityFile.negdatestamp =negdatestamp.getDatum();
Hey -
I've been running this through some testing and found a minor problem. In RAD, the calculation of 1/1/2200 00:00 - tod() appears to be adjusted for timezone. ie, if I go into the sc.activity RAD app with an operator set to US/Eastern, the calculation is 12/31/2100 19:00 - tod(). The result is that when I used this function, activities added via javascript and ones added via activityaction are just slightly off. I had to make a few corrections to fix this.
Replace these two lines:
withCode:var future =newDate(2200,1,1,1); var delta = future -now - (30*86400000);
I tested this in a 6.1.2 system.Code:var future = new Date(2200,1,1); var offset = future.getTimezoneOffset(); var offsetmsec = offset * 60 * 1000; var delta = future - now - (30 * 86400000) - offsetmsec;
I solved it similar. I need the calculated time (today - 1 day) in a select query:
var alert = new SCFile("Alert");
var XDate = new XMLDate( new Date() );
var SCNow = XDate.getSCDateTimeString(); // es soll nicht einfach sein: erst wandeln dann handeln
var X5 = new Date();
// 86400000 = 24 h * 60 min * 60 s * 1000 ms
X5.setTime(X5.getTime() - 24 * 60 * 60 * 1000);
var XDate5 = new XMLDate( X5 );
var SCNow5 = XDate5.getSCDateTimeString(); // es soll nicht einfach sein: erst wandeln dann handeln
var rc = alert.doSelect("alert.name#\"Email\" and alert.time<='" + SCNow + "' and alert.time>='" + SCNow5 + "'"); // ein Tag Fenster prüfen
Greetings All,
Has anyone out there managed to perform JS date/time calculations with the work calendars functionality that you normally get out of RAD apps like:
calendar.calc.date.pos|neg|fc
I have been tearing my hair out trying 'callrad' to call the RAD apps as well as trying to call scripts that call the RAD apps but I am getting a stone wall each and every time.
Thanks.
Hi guys, i am creating activity records via JScript but have a bit of a problem. Wondered if any of you have came up with the solution for this one:
SC stores the negdatestamp as something like this: 71013 03:11:15
I calculated it as mentioned above but come up with something like this: 07/09/2161 03:30:31
The question is how to transform my calculation to the right format.
My thanks in advance
ok so the problem wasn't so big after all. All I did was this:
works like a charm.Code:var now =new Date(); var future =new Date(2200,1,1,1); var delta = future -now - (30*86400000)-3600000; var days =String(parseInt(delta/86400000)); var hours =String(parseInt((delta - (days*86400000))/3600000)); var minutes =String(parseInt((delta - (days*86400000) - (hours*3600000))/60000)); var seconds =String(parseInt((delta - (days*86400000) - (hours*3600000) - (minutes*60000) )/1000)); if(hours<10) hours="0"+hours; if(minutes<10) minutes="0"+minutes; if(seconds<10) seconds="0"+seconds; var negdatestamp =(days+" "+hours+":"+minutes+":"+seconds); var date1 = new Date(); date1=system.functions.val(negdatestamp,3); fActivity.negdatestamp = date1;
I was trying to force it to store a date in this format: 71013 03:11:15 but it was not needed since it stores it in the table in the correct format.
Last edited by rdaniel; 2008-07-24 at 18:18.
I've been using what tommy wrote in post 2 with my modification in post 6 for a while now without any issues.
We are using Service Manager 9.20. I had to make a slight modifications to Tommy's script to get the negative timestamp calculation to work out correctly for ordering of activity updates.
Eventually I found the answer to my calculation problem in the RAD application update.change.activity.
The future date calculation in our system is based on '12/31/2199 10:00:00' instead of '01/01/2200 01:00:00'
The fix was a simple change to one line in the script posted by Tommy above.
Change line:
To:Code:var future =new Date(2200,1,1,1);
Code:var future = new Date(2199,12,31,10);
The code:
var now =new Date();
var future =new Date(2200,1,1,1);
fActivity.negdatestamp = system.functions.val(((future - now)/1000),3);
Worked fine for me.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks