Update google calendar description javascript - javascript

Im working on an application for google calendar. I can get calendars, create events and display them but i cannot seem to update a specific calendars metadata.
I have this function
function setCalendarDescription(calendarId) {
var send ={
"resource" :{
"description" : "test"
}
};
console.log(send);
var request = gapi.client.calendar.calendars.update({
'calendarId': calendarId,
'resource': send
});
console.log(request);
request.execute(function(resp) {
alert("updated description in calendar");
});
}
And im calling it in this function
function listCalendars() {
var request = gapi.client.calendar.calendarList.list();
request.execute(function(resp) {
var calendars = resp.items;
var counter = 0;
//console.log(calendars);
for (i = 0; i < resp.items.length; i++) {
var calendar = resp.items[i];
var calId = calendar.id;
var calName = calendar.summary;
var accessRole = calendar.accessRole;
if (accessRole == "owner") {
var ulEvents = document.getElementById("events");
var nH3 = document.createElement('ul');
var nH3Text = document.createTextNode("Upcoming events for calendar " + calName + ":");
nH3.appendChild(nH3Text);
nH3.setAttribute("id", "upcoming" + i);
ulEvents.appendChild(nH3);
listUpcomingEvents(calId, counter);
calendarArray[counter] = calendar;
setCalendarDescription(calId);
counter++;
}
}
});
}
I have looked here for a solution and the web but have yet to find one.
If anyone has some directions i'd appreciate it.
Thanks

I did not look thoroughly enough the documentation and the answer was right there.
It's not enough to only supply a description for the calendar, you need to supply
description string Description of the calendar.
location string Geographic location of the calendar as free-form text.
summary string Title of the calendar.
timeZone string The time zone of the calendar.

Related

How to add a unique Google Meet link for every event creation (within a specific if statement) using Google Apps Script

var event_title = "";
var desc = "";
var today = new Date();
var thirtyMinutes = new Date(today);
thirtyMinutes.setMinutes(today.getMinutes() + 30);
var event = calendar.createEvent(event_title, today, thirtyMinutes, { description: desc }).setVisibility(CalendarApp.Visibility.PRIVATE).setColor("11").addPopupReminder(10);
var example_description = 'example description';
if (interview_type == 'Example Interview') {
event.setTitle('Example Title');
event.setDescription(example_description + "");
}
How do I add a newly generated Google Meet link for each event that is generated ONLY for the if statement that is nested within:
if (interview_type == 'Example Interview') {
event.setTitle('Example Title');
event.setDescription(example_description + "");
}
I found this solution in another answer but I can't seem to configure it for my use case where it doesn't disrupt the current event creation settings that I have set up and to make it generate a new one for every single event creation, as well as to keep it within that if statement that triggers a specific type of event creation:
var event = {
"summary": summary,
 "start": {
   "dateTime": start.toISOString()
   },
"end": {
  "dateTime": end.toISOString()
  },
   "conferenceData": {
  "createRequest": {
    "conferenceSolutionKey": {
     "type": "hangoutsMeet"
  },
    "requestId": id
   }
}
  };
 event = Calendar.Events.insert(event, 'primary', {
"conferenceDataVersion": 1});
 return event.hangoutLink;
Thank you
You can refer to this sample code:
function createEvent() {
var calendarId = 'c_9cdqeqqluk7vsessartxxxxxx';
var calendar = CalendarApp.getCalendarById(calendarId);
var interview_type = 'Example Interview';
var event_title = "";
var desc = "";
var today = new Date();
var thirtyMinutes = new Date(today);
thirtyMinutes.setMinutes(today.getMinutes() + 30);
var event = calendar.createEvent(event_title, today, thirtyMinutes, { description: desc })
.setVisibility(CalendarApp.Visibility.PRIVATE).setColor("11").addPopupReminder(10);
Logger.log('Event ID: ' + event.getId());
var example_description = 'example description';
if (interview_type == 'Example Interview') {
event.setTitle('Example Title');
event.setDescription(example_description + "");
//Add Meet Conference
var tmpEvent = {
conferenceData:{
createRequest:{
conferenceSolutionKey:{
type: "hangoutsMeet"
},
requestId: charIdGenerator()
}
}
}
//remove #google.com from the iCalUID of the event
var eventId = event.getId().replace("#google.com","");
Logger.log(eventId);
Calendar.Events.patch(tmpEvent,calendarId,eventId,{conferenceDataVersion:1});
}
}
function charIdGenerator()
{
var charId ="";
for (var i = 1; i < 10 ; i++)
{
charId += String.fromCharCode(97 + Math.random()*10);
}
//Logger.log(charId)
return charId;
}
Pre-requisite:
You need to enable Advanced Calendar Service in Apps Script,
To enable advanced services:
Select Google Calendar API in Step 4.
What it does?
When the interview_type is set to 'Example Interview', We will create an event resource having a createRequest in its body. It will require 2 inputs:
conferenceSolutionKey type which is set to hangoutsMeet
requestId which is a client-generated unique ID for this request. Clients should regenerate this ID for every new request. If an ID provided is the same as for the previous request, the request is ignored.
Note:
I just copied some function I found online that generates a random string, and used that string as the requestId
Once the event resource was created, We need to get the event id by removing the "#google.com" sub-string in the iCalUID returned by CalendarEvent.getId() method.
Note:
CalendarEvent.getId() gets the unique iCalUID of the event. Note that the iCalUID and the event id used by the Calendar v3 API and Calendar advanced service are not identical and cannot be used interchangebly.
Lastly, we need to use Calendar.Events.patch(resource: Calendar_v3.Calendar.V3.Schema.Event, calendarId: string, eventId: string, optionalArgs: Object): to update our newly created event.
OUTPUT:

How to click on a dynamically created link to then create a new dynamic page from that link?

I wrote an custom API(node.js app) that gets the info about the blogs from medium.com, right now there is
the author/main pic of the article,
title,
link to the article on medium.com(redundant),
the entire article text, in the JSON output.
Sample API/JSON:
{
"img": [
"https://upload.wikimedia.org/wikipedia/commons/4/42/Blog_%281%29.jpg"
],
"title": [
"The old and the new or not so new: Java vs JavaScript"
],
"link": [
"https://medium.com/#aki9154/the-old-and-the-new-or-not-so-new-java-vs-javascript-760f84e87610?source=rss-887f1b1ddb75------2"
],
"desc": [
"<p>It’s funny how the name JavaScript makes you believe that it is somehow..."
]
}
Then i am polling this API/JSON and spitting out the output in a thumbnail format, basic html for now(no design/CSS).
Where i am stuck is when a user clicks on a thumbnail and i need to make sure that i display the correct article?!
For which i need to display a new page when the thumbnail/article is clicked, i can use #4 from JSON above as an output for that dynamically created new page and put it out nicely)
The issue that i am facing now is how to dynamically produce the correct article when the dynamically created link is clicked?
Right now nothing happens when i click on the thumbnail and that's what this project link displays...
I did some stackoverflow research and read some jQuery docs(event propagation and more...) and was able to make changes to the index.js, below is how it looks like but nothing works, any help will be appreciated...
index.js:
$(function () {
var desc = "";
function newWin() {
var w = window.open();
$(w.document.body).html('<p>'+desc+'</p>');
}
var $content = $('.cards-in-grid');
var url = 'link-for private use now';
$.get(url, function (response) {
var output = '';
console.log(response);
$.each(response, function (k, item) {
title = item.title;
var author = item.img;
desc = item.desc;
output += '<li><img src="'+author+'" alt=""><h2>' + title + '</h2></li>';
$(".cards-in-grid ul").on("click", "li", function(){
newWin;
});
return k;
});
$content.html(output);
});
});
`
$(function () {
var $content = $('.cards-in-grid');
var url = 'link-for private use now';
$.get(url, function (response) {
var output = '';
var list = "li";
$.each(response, function (k, item) {
var listNum = list+k;
var idy = "#"+listNum;
var desc = "";
title = item.title;
var author = item.img;
desc = item.desc;
//GIVE ID to each LI using a variable
output += '<li id="'+listNum+'"><img src="'+author+'" alt=""><h2>' +
title + '</h2></li>';
$content.html(output);
$content.on("click",idy, function(){
var w = window.open();
$(w.document.body).html('<p>'+desc+'</p>');
});
return k;
});
});
});
This worked perfectly, some thinking and pondering and was able to make it work!!
Kindly Upvote the answer, if it helped you! Thanks!

Send Email Checkbox on Attendee Sublist user event script

In NetSuite I have a custom record for keeping track of our safety meetings, from the record, I have a user-event script, BEFORE SUBMIT FUNCTION, running to create an event record. On the Event record -> attendee sublist, I am able to add the attendees, but I am unable to set the sendemail checkbox. Any insight would be appreciated.
/*
user event script
before record submit
creates a new event record based off this safety meeting record.
*/
function createSafetyMeetingEventRec(type){
if(type=="create")
{
try
{
//get values from the safety meeting record
var altName = nlapiGetFieldValue('altname');
var message = nlapiGetFieldValue('custrecord53');
var local = nlapiGetFieldValue('custrecord56');
var date = nlapiGetFieldValue('custrecord51');
var time = nlapiGetFieldValue('custrecord52');
//name of the event record
var eventTitle = 'SM-' + altName;
//create the event record
var eventRec = nlapiCreateRecord('calendarevent');
//set the event record field values
eventRec.setFieldValue('title', eventTitle);
//script search for the Safety Committee group members in netsuite
var entitygroupSearch = nlapiSearchRecord("entitygroup",null,
[
["internalid","anyof","120147"]
],
[
new nlobjSearchColumn("entityid","groupMember",null),
new nlobjSearchColumn("internalid","groupMember",null)
]
);
//get who created the event, this user is automatically on the attendee list, and cannot be added again.
var eventUserSet = eventRec.getLineItemValue('attendee', 'attendee', 1);
for(var i = 0; i < entitygroupSearch.length; i++){
var newAt = eventRec.getLineItemCount('attendee') + 1;
var intIDuser = entitygroupSearch[i].getValue("internalid","groupMember",null);
if(intIDuser != eventUserSet){
eventRec.setLineItemValue('attendee', 'sendemail', newAt, 'T');
eventRec.setLineItemValue('attendee', 'attendee', newAt, intIDuser);
}else{
continue;
}
}
//set the resource calendar to Service Calendar, 3 is the internal id of the service calendar resource
var newAtResource = eventRec.getLineItemCount('resource') + 1;
eventRec.setLineItemValue('resource', 'resource', newAtResource, '3');
var eventId = nlapiSubmitRecord(eventRec, true);
}catch(err)
{
nlapiLogExecution("error","Error Creating Event Record From Safety Record ","Details: " + err.message);
}
}//end if
}
I think you also need
eventRec.setFieldValue('sendemail', 'T');
before the submit

How can I get the data entered into a Google Form emailed to me?

I made some modifications to a Google Script I found online, but not knowing how to script so well, I'm sure I'm missing something here.
My goal is to have all the information submitted through a Google Form to then be emailed to me or a group I'll create.
This script here does email me the info, but it's all added as a single line without even mentioning the questions.
I'm a total newb, but I'm sure this could be solved with some kind of command or event that I'm unaware of.
Take a look:
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First column of data to process
var numRow = 1; // Number of columns to process
var dataRange = sheet.getRange(startRow, 1, numRow, 10)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var message1 = row[1,2,3,4,5];
var message2 = row[2];
var message3 = row[3];
var message4 = row[4];
var message5 = row[5];
var message6 = row[6];
var message7 = row[7];
var message8 = row[8];// Second column
var emailSent = row[10]
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = "New Hire On The Way!";
MailApp.sendEmail("itgroup#mycompany.com",subject,message1+message2+message3+message4+message5+message6);
sheet.getRange(startRow + i, 10).setValue(EMAIL_SENT);
}
}
}
That whole "EMAIL_SENT" was my attempt at having the script not resend info that was already entered.
If there is a better way of doing this, I'd love to hear it.
Thank you so much!
You can set this function as a trigger for onFormSubmit in the response sheet.
Source: Get Google Forms data in an Email Messages
function SendGoogleForm(e) {
var email = Session.getActiveUser().getEmail();
var subject = "Google Docs Form Submitted";
var s = SpreadsheetApp.getActiveSheet();
var columns = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
for ( var keys in columns )
message += columns[keys] + ' :: '+ e.namedValues[columns[keys]] + "\n\n";
MailApp.sendEmail(email, subject, message);
}
if your just wanting the email to have a little more structure you can just add html to the individual messages. Depending how crazy your want to get is up to you. Here is a simple change that you can try it should have a little more structure. Replace this with your if statement
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = "New Hire On The Way!";
MailApp.sendEmail("itgroup#mycompany.com",subject,message1+"<br />"+"<br />"+"<br />"+message2+"<br />"+"<br />"+"<br />"+message3+"<br />"+"<br />"+"<br />"+message4+"<br />"+"<br />"+"<br />"+message5+"<br />"+"<br />"+"<br />"+message6+"<br />"+"<br />"+"<br />");
sheet.getRange(startRow + i, 10).setValue(EMAIL_SENT);
}
All I did here is add breaks between your messages. This should create some spaces. You can always go crazy with inline css and html. www.w3schools.com is always a great place to start for beginners. Good Luck and happy coding!

Retrieving Start/End Time fields with SharePoint Client Object Model

I have some experience using the SharePoint Client Object Model to retrieve text fields and URLs/images from lists in SP 2013. I'm currently trying to do something similar with a calendar. I have been able to successfully retrieve Title and Location fields without any issue, but the Start and End Time fields I am not able to retrieve. I cannot figure out what exactly the issue is. Additionally, I can read Created and Modified with no problems. Here is the relevant code:
function retrieveListItemsCal() {
var clientContextCal = new SP.ClientContext.get_current();
var oListCal = clientContextCal.get_web().get_lists().getByTitle('Calendar');
var camlQueryCal = new SP.CamlQuery.createAllItemsQuery();
AllItemsCal = oListCal.getItems(camlQueryCal);
clientContextCal.load(AllItemsCal);
clientContextCal.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededCal), Function.createDelegate(this, this.onQueryFailedCal));
}
function onQuerySucceededCal(sender, args) {
var listItemInfo = '';
var listItemEnumeratorCal = AllItemsCal.getEnumerator();
var htmlCal = '';
htmlCal+="<div id='CalHeader'>Upcoming Events</div>\
<div id='CalDivider'></div>\
<div id='CalContainer'>";
while(listItemEnumeratorCal.moveNext()) {
var oListItemCal = listItemEnumeratorCal.get_current();
/*htmlCal+="<div class='CalItem'>\
"oListItemCal.get_item('Start Time')"\
</div>";*/
alert(oListItemCal.get_item("Start Time").format("MMMM d, yyyy"));
}
htmlCal+="</div>";
$("#CalSpace").append(htmlCal);
}
function onQueryFailedCal(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
$(document).ready(function(){
SP.SOD.executeFunc("sp.js", "SP.ClientContext", retrieveListItemsCal);
});
And here is a screenshot of the list columns: http://i.imgur.com/8IK4KTO.png
I have resolved my issue. I ran the following PowerShell queries (found here http://techtrainingnotes.blogspot.com/2012/10/sharepointfinding-column-display-and.html):
$web = Get-SPWeb SiteUrl
$list = $web.Lists["Announcements"]
$list.fields | select Title, InternalName, Hidden, CanBeDeleted | sort title | ft -AutoSize
The internal names of the Start Time and End Time fields are EventDate and EndDate, respectively.

Categories