How to create calendar event using server-side javascript code?
Here is the code for creating calendar event.
var node = companyhome.childByNamePath("Sites/demo/calendar");
var myEvent = node.createNode(new Date().getTime() + "-" + Math.round(Math.random()*10000) + ".ics", "ia:calendarEvent")
myEvent.properties["ia:whereEvent"] = "Where event";
myEvent.properties["ia:descriptionEvent"] = "This is the description";
myEvent.properties["ia:whatEvent"] = "What event";
var fromDate = new Date();
var fromISODate = utils.toISO8601(fromDate);
myEvent.properties["ia:fromDate"] = fromISODate;
var toDate = new Date();
toDate.setHours(toDate.getHours() + 3);
var toISODate = utils.toISO8601(toDate);
myEvent.properties["ia:toDate"] = toISODate;
myEvent.save();
logger.warn("Created new calendar event: " + myEvent.nodeRef);
Related
I'm to figure out how to code so that the link opens into a new window? Is this the correct way to do that?
<script>
var copyright = "© ";
var d = new Date();
var n = d.getFullYear();
var db = " Doing Business";
var str = new String(" Link");
document.write(copyright + n + str.link("https://www.google.com"));
document.write(db);
</script>
Please stop using String.link. It's old, deprecated, and smelly. It also doesn't support what you are trying to do.
You can construct a link with the appropriate target attribute (read more) to open in a new tab as follows:
var myLink = "<a target='_blank' href='https://www.google.com'>Link</a>";
document.write(copyright + n + " " + myLink);
i have problem when i try make log for everytime date change it make new file and stop log when end date , for example
20200709_Chatlog.txt for
2020-07-09 21:56:12:91 - connect null
2020-07-09 21:56:15:952 - a user connected
20200710_Chatlog.txt for
2020-07-10 21:56:12:91 - connect null
2020-07-10 21:56:15:952 - a user connected
but my file is always overwrite in the same file date like this
20200709_Chatlog.txt
2020-07-09 21:56:12:91 - connect null
2020-07-09 21:56:15:952 - a user connected
2020-07-10 21:56:12:91 - connect null
2020-07-10 21:56:15:952 - a user connected
, but everytime i restart the server new file created
my code is
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function logDate(){
var d = new Date();
var yy = addZero(d.getFullYear());
var mm = addZero(d.getMonth() + 1);
var dd = addZero(d.getDate());
var h = addZero(d.getHours());
var m = addZero(d.getMinutes());
var s = addZero(d.getSeconds());
var ms = addZero(d.getMilliseconds(), 3);
var tanggal = "";
return tanggal = +yy+ "-" +mm+ "-" +dd+ " " +h+ ":" +m+ ":" +s+ ":" +ms + " ";
}
function fileDate(){
var d = new Date();
var yy = addZero(d.getFullYear());
var mm = addZero(d.getMonth() + 1);
var dd = addZero(d.getDate());
var tanggal = "";
return tanggal = +yy+ "" +mm+ "" +dd+ "_";
}
var fs = require('fs');
var util = require('util');
var logFile = fs.createWriteStream(fileDate()+'Chatlog.txt', { flags: 'a' }); // 'w' to truncate
var logStdout = process.stdout;
console.log = function () {
logFile.write(logDate()+" - " + util.format.apply(null, arguments)+ '\n');
logStdout.write(logDate()+" - " + util.format.apply(null, arguments) + '\n');
}
console.error = console.log;
am i do something wrong, please help , and thanks for helping , sorry if my english bad
I have Google Apps Script which inputs events into my google calendar from a spreadsheet. Anyone know how to have the script set a row's background color to green & last column value to "complete" only if it's been ran through the loop?
Currently I have it just setting the full range to these parameters, but would like to prevent certain rows from being included if the last column is equal to "Invalid".
function inputEvents() {
var spreadsheet = SpreadsheetApp.getActiveSheet();
var calendarId = spreadsheet.getRange("B1").getValue();
var calendar = CalendarApp.getCalendarById(calendarId)
var lr = spreadsheet.getLastRow();
var count = spreadsheet.getRange("A3:AF"+lr+"").getValues();
for (x=0; x<count.length; x++) {
var events = count[x];
var name = events[2];
var phone = events[3];
var email = events[4];
var title = events[5];
var startTime = events[6];
var endTime = events[7];
var description = events[8];
var location = events[9];
var eventId = events[31];
var contactHeader = "CONTACT:";
var descriptionHeader = "DESCRIPTION:";
var complete = "Complete";
var invalid = "Invalid";
var info =
contactHeader.bold() + "\n"
+ name + "\n"
+ phone + "\n"
+ email + "\n"
+ "\n" + descriptionHeader.bold() + "\n"
+ description;
var options = {
'guests' : email,
'description': info,
'sendInvites': 'True',
'location': location,
}
if (eventId != complete && eventId != invalid){
calendar.createEvent(title, startTime, endTime, options);
spreadsheet.getRange("AF3:AF"+lr+"").activate().setValue('Complete');
spreadsheet.getRange("A3:AF"+lr+"").activate().setBackground('#d9ead3');
}
}
}
You're using the setValue and setBackground methods to the entire range, you need to apply them only to the range you're interested in, try setting a currentRow variable and change the range you're getting inside your if statement, like this:
var currentRow = 3 + x;
if (eventId != complete && eventId != invalid){
calendar.createEvent(title, startTime, endTime, options);
spreadsheet.getRange("AF" + currentRow).setValue('Complete');
spreadsheet.getRange("A"+ currentRow + ":AF" + currentRow).setBackground('#d9ead3');
}
Below I have the code for xul addon which works expectedly.
i.e. shows username and password input at the browser startup and whenever the topic is http-on-examine-response it validates and write in specified file.
But when I try to convert it to a bootstrapped extension it won't even show the username password input at the browser startup and nothing is showing in the console when I compile and run.
I couldn't figure out the wrong thing after I changed the components... to Cu/Cc/etc.
I referred below links
https://developer.mozilla.org/en/Add-ons/Bootstrapped_extensions
What does paragraph about figuring out XUL elements mean in MDN document: "How to convert an overlay extension to restartless"
https://github.com/Noitidart/l10n/tree/xhtml-xul
Below is my code:
const {Cc, Ci, Cu, components} = require("chrome");
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
function Tdatacounter() {
var Tdatacounter = {
observe: function(subject, topic, data) {
if (topic == "http-on-examine-response") {
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
if (httpChannel.responseStatusText == "OK")
{
var buffer = httpChannel.URI.spec;
var pw = buffer.search("pub.tdata.com/releasepic");
if (pw > 0)
{
var date = new Date();
var TimeStamp = date.toLocaleString();
var pfum = buffer.search("flag=unmap");
if (pfum > 0 )
{
var flagname = "unmap";
var flagnum = 4;
}
if (flagnum > 0)
{
buffer += "^" + ThisUserName + "^" + ThisComputerName + "^" + TimeStamp + "^" + flagname + "\r\n";
fos.write(buffer, buffer.length);
}
}
}
}
}
};
var nsIEnvironment = Cc["#mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
var prompts = Cc["#mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
var usernamelist = ["user1","user2","user3"];
var passlist = ["e%cd1","kowgirl23","bhava1204"];
var ThisUserName = null;
var username = {value: "UserName"}; // default the username to user
var password = {value: "pass"}; // default the password to pass
var check = {value: false}; // default the checkbox to true
var GetUserName = prompts.promptUsernameAndPassword(null, "ProcName", "Enter username and password:", username, password, null, check);
while (GetUserName === true) {
var a = usernamelist.indexOf(username.value);
var b = passlist[a];
if (password.value == b) {
var ThisUserName = username.value;
break;
} else {
var GetUserName = prompts.promptUsernameAndPassword(null, "ProcName", "Enter username and password:", username, password, null, check);
}
}
if (ThisUserName !== null) {
var ThisComputerName = nsIEnvironment.get("ComputerName");
var FileUtils = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils;
var d = new Date();
var dd = d.getDate();
if (dd < 10)
dd = "0" + dd;
var mm = (d.getMonth()+1);
if (mm < 10)
mm = "0" + mm;
var yyyy = d.getFullYear();
var file = new FileUtils.File( "\\\\STJ\\Proc1\\-\\" + yyyy + "\\" + mm + "\\" + dd );
if (!file.exists()) {
file.create(file.DIRECTORY_TYPE, 0755);
}
var filename = "HM_" + ThisUserName + yyyy + "-" + mm + "-" + dd + ".txt";
file.append(filename);
var fos = Cc["#mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
// PR_WRONLY | PR_CREATE_FILE | PR_APPEND
fos.init(file, 0x02 | 0x08 | 0x10, -1, 0);
var date = new Date();
var TimeStamp = date.toLocaleString();
var StartTime = "LoginTime=" + TimeStamp + " at " + ThisComputerName + "\r\n";
fos.write(StartTime, StartTime.length);
var observerService = Cc["#mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
observerService.addObserver(Tdatacounter, "http-on-examine-response", false);
}}
Tdatacounter.prototype.classID = components.ID('{d4a9bb50-b9b2-11e0-a4dd-0800200c9a66}');
Tdatacounter.prototype.classDescription = 'tdata Counter';
Tdatacounter.prototype.contractID = '#tdata/TdataCounter;1';
var NSGetFactory = XPCOMUtils.generateNSGetFactory([TdataCounter]);
I figured out what I've missed. As a beginner in firefox javascript, I missed to add 'register', 'unregister' functions. What a silly mistake I did? Phew. anyhow I hope this answer will be helpful for the novices like me.
Thank you.
Can you please say whats wrong with this? I have a javascript function called which creates a new events array and tries to refresh fullcalendar.
var events=new Array();
var numberofevents = this.serviceVariableGetDates.getTotal();
for (i=0;i<numberofevents;i++)
{
//alert("numbrr:" + i);
var dates=this.serviceVariableGetDates.getItem(i);
console.log(dates.getData());
var start_date = dates.getValue("c0");
var end_date = dates.getValue("c1");
var event_name = dates.getValue("c2");
//var EventEntry = [ 'title: '+ event_name, 'start: '+ start_date,'end: '+ end_date ];
events['title'] = event_name;
events['start'] = start_date;
events['end'] = end_date;
events['color'] = "blue";
this.label1.setCaption(start_date);
//EventArray.push(EventEntry);
console.log(events['title']);
}
$('#calendar').fullCalendar('addEventSource',events);
$('#calendar').fullCalendar('rerenderEvents');
The calendar does not refresh or show the events in the events array....Through different debug methods I am sure that the events array is populated with the correct data. The start_date is for example "1307318400000" which is in the unix timestamp format. The fullcalendar is being initialized somewhere else in the begining (when the page load) and it stays unchanged even though addeventsource and rerenderevents methods are called.
according to the docs you need to put array of events to the addEventSource function
event must be an Event Object with a title and start at the very
least.
var events=new Array();
var numberofevents = this.serviceVariableGetDates.getTotal();
for (i=0;i<numberofevents;i++)
{
//alert("numbrr:" + i);
var dates=this.serviceVariableGetDates.getItem(i);
console.log(dates.getData());
var start_date = dates.getValue("c0");
var end_date = dates.getValue("c1");
var event_name = dates.getValue("c2");
//var EventEntry = [ 'title: '+ event_name, 'start: '+ start_date,'end: '+ end_date ];
event = new Object();
event.title = event_name; // this should be string
event.start = start_date; // this should be date object
event.end = end_date; // this should be date object
event.color = "blue";
event.allDay = false;
this.label1.setCaption(start_date);
//EventArray.push(EventEntry);
console.log(events['title']);
events.push(event);
}
$('#calendar').fullCalendar('addEventSource',events);
//$('#calendar').fullCalendar('rerenderEvents');
Hope this will help!