CalendarEvent color - colors

When I create a Calendar Event manually, there is the possibility to give special colors to the event.
How can I access / change this color with a script? Searched all docs but found color only on the calendar-level, not on the event-level.

"colorId" is a string property of an event resource.
https://developers.google.com/google-apps/calendar/v3/reference/events#resource

The new Advanced Calendar Service allows you to do this now. Check out sample code under "Creating events" header:
https://developers.google.com/apps-script/advanced/calendar
I will paste it below in case the change the help page:
function createEvent() {
var calendarId = 'primary';
var start = getRelativeDate(1, 12);
var end = getRelativeDate(1, 13);
var event = {
summary: 'Lunch Meeting',
location: 'The Deli',
description: 'To discuss our plans for the presentation next week.',
start: {
dateTime: start.toISOString()
},
end: {
dateTime: end.toISOString()
},
attendees: [
{email: 'alice#example.com'},
{email: 'bob#example.com'}
],
// Red background. Use Calendar.Colors.get() for the full list.
colorId: 11
};
event = Calendar.Events.insert(event, calendarId);
Logger.log('Event ID: ' + event.getId());
}
/**
* Helper function to get a new Date object relative to the current date.
* #param {number} daysOffset The number of days in the future for the new date.
* #param {number} hour The hour of the day for the new date, in the time zone
* of the script.
* #return {Date} The new date.
*/
function getRelativeDate(daysOffset, hour) {
var date = new Date();
date.setDate(date.getDate() + daysOffset);
date.setHours(hour);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
return date;
}

The other answer refers to the calendar API that you can eventually access but it's not part of the standard calendar methods available in GAS.
You can simplify your life by making use of a Library that has been developed by Romain Vialard (gas top contributor) and that is available on his website along with an application I wrote that uses it extensively
edit : there is also an enhancement request on this on the issue tracker that I raised a while ago, feel free to star it.

Related

Add multiple sameday events Calendar in sheets - Script AutoRun [duplicate]

I'm trying to create calendar events in sheets using Google App Script (I'm very new to this). The sheet contains details of the event (date, time, event title, and guest list) as well as the calendar ID (this is a training calendar). I want to make it simple for the end-user to fill in the information on the sheet, click 'schedule now' and the script run and send the events out to all email addresses mentioned in the guest list.
Here is an example of the sheet:
Here is a copy of the code (I found this on the Google Developer website and tried to adapt it to add guests but haven't been able to get it working and really not sure where to go with this. Ideally, I'd like the guest list to come from the sheet and not be written into the code as an option.
function scheduleTraining() {
var spreadsheet = SpreadsheetApp.getActiveSheet();
var calendarId = spreadsheet.getRange("C3").getValue();
var eventCal = CalendarApp.getCalendarById(calendarId);
Logger.log(eventCal)
var signups = spreadsheet.getRange("A5:C20").getValues();
for (x=0; x<signups.length; x++) {
var shift = signups[x];
var startTime = shift[0]
var endTime = shift[1]
var title = shift[2]
eventCal.createEvent(title, startTime, endTime, {
location: 'remote',
description: 'snacks provided',
})
}
}
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('Schedule Training')
.addItem('Schedule Now', 'scheduleTraining')
.addToUi();
}
If anyone can help with this or has any ideas on how to do this better, I'm all ears!
Thanks!
Issues:
The dates in your spreadsheet file are strings/texts. You can verify that if you do =isDate(A7). If the latter returns FALSE then you don't have a valid date object. If you see the official documentation you need to pass date objects and not date texts.
Another remark I have is that your range is "A5:C20" but you should start from A7. Row 5 and 6 don't contain the information required, according to your screenshot.
Question based on your comment:
how I can include inviting the guests when it's run
Again according to the documentation, you can add guests using the advanced parameters options and in particular guests:
eventCal.createEvent(title, startTime, endTime, {
location: 'remote',
description: 'snacks provided',
guests: 'test1#gmail.com,test2#gmail.com'
})
guests is a type of string that contains a comma-separated list of email addresses
that should be added as guests.

Get Receipt number on Stripe C#

Please how can I get the receipt number on Stripe with c#
My image :
https://www.casimages.com/i/191231053006538388.png.html
Maybe with a Session ID ?
You'd access the Charge object and it's a field on that resource.
You say you're using Checkout. So the Charge is under session.payment_intent.charges.data[0]. It requires a little digging to get it but it's all there. I'd suggest that when you receive the event as part of fulfilling the order etc, retrieve the Session(stripe.com/docs/api/checkout/sessions/retrieve) and expand "payment_intent". Then session.PaymentIntent.Charges.Data[0].ReceiptNumber is the value you're looking for.
static void CheckoutSessionReceiptEmail()
{
var service = new Stripe.Checkout.SessionService();
var session = service.Get(
"cs_test_nHUZtpUvaI80YAKGgCMGyeHfjQ6nMtUhVLeVpowWsgpfyGujccGxnAuJ",
new Stripe.Checkout.SessionGetOptions
{
Expand = new List<string> { "payment_intent" }
}
);
Console.WriteLine(session.PaymentIntent.Charges.Data[0].ReceiptNumber);
}

SuiteScript Script sending statements

I couldn't find an answer to this in docs or here. Is it possible to script sending statements to customers? thanks for any help you can give.
Yes, but it's even easier to do it with a workflow. We created a custom field for a 'Statement Contact' and set up a scheduled workflow based on a 'Saved Search Filter' which basically checks that the customer has a balance. There is one state which contains a single 'Send Email' action. The 'Send Email' action has the option to 'Include Statement'. It fires on the 4th day of each month - you can set this or any other parameter to whatever suits you. This works fine for us, so I hope it helps you.
I found this in SuiteAnswers, it is enough for my purposes.
function printStatement()
{
//this is is the customer id
var id = nlapiGetRecordId();
var email = nlapiGetFieldValue('custentity_accounting_email');
//create an array to set the STATEMENT properties(optional)
var sdate = new Array();
sdate.startdate = '11/01/2015'; // replace it as per requirement
sdate.statementdate = '11/30/2015'; // replace it as per requirement
sdate.openonly = 'T'; // replace it as per requirement
sdate.formnuber = 112; // replace it as per requirement
//print the statement to a PDF file object
var file = nlapiPrintRecord('STATEMENT', id, 'PDF', sdate);
//send the PDF as an attachment
nlapiSendEmail('-5', email, 'Regular Statement', 'Please see attached Statment', null, null, null, file); //change the value of author id.
}

Does toLocaleTimeString in Node.js support the hour12 option?

I can't seem to get hour12 time working in node.js, however in the browser (Chrome) it's working just fine.
Node.js in terminal
var date = new Date();
var d12 = date.toLocaleTimeString('en-US', {hour12:true});
var d24 = date.toLocaleTimeString('en-US', {hour12:false});
console.log(d12) // output 13:43:38
console.log(d24) // output 13:43:38
Both yeild the same result:
13:43:38
Update
Adding fiddle to prove it works in browser
Could someone point me to the docs that explain why, or tell me what I'm doing wrong?
It's not just you. I tried running the same chunk in Node.js and couldn't get a way to print it in 12 hour format easily.
After doing some Googling, it seems like Moment.js is a popular tool for manipulating and displaying time and days. If you need to manipulate a lot of time/dates, it may be worth checking out, Moment.js.
// with Moment
var moment = require('moment');
console.log(moment().format('hh:mm'));
Otherwise,
// just one of many ways to do it in Javascript
function hour12 (hour) {
var mod = hour % 12;
if (mod < 10) {
return '0'.concat(mod);
} else {
return mod;
}
}
console.log(new Date().toLocaleTimeString().replace(/[\d]+/, hour12(date.getHours())));
EDIT I answered this question late at night, and realized I sort of missed the mark on addressing the question.
Since Node.js is based off Chrome's v8 JavaScript engine, I started poking around in the source code. I can't see a place where it takes into account arguments passed to it.
Code is here, toLocaleTimeString is line 324. In comparison, I looked around Mozilla's SpiderMonkey engine and it at a glance, it seems to account for this.
You can use toLocaleDateString and toLocaleTimeString to format times and dates. The first parameter passed to these methods is a locale value, such as "en-us". The second parameter, where present, specifies formatting options, such as the long form for the weekday.
I've used Chrome and works well.
var date = new Date(Date.UTC(2016, 3, 7, 14, 30, 0));
var options = {
weekday: "long", year: "numeric", month: "short",
day: "numeric", hour: "2-digit", minute: "2-digit"
};
document.write(date.toLocaleTimeString("en-US", options));
https://msdn.microsoft.com/en-us/library/ff743760(v=vs.94).aspx

Netsuite: how can I add an employee with a role, access, and a password via SuiteScript?

This code work great for creating the employee, but the password and giveAccess fields are not set:
function CreateEmployee() {
nlapiLogExecution('DEBUG','running create employee',1);
var employeeRec = nlapiCreateRecord('employee');
employeeRec.setFieldValue('lastname', 'Aloe');
employeeRec.setFieldValue('firstname', 'Danny');
employeeRec.setFieldValue('email', 'test9475#test232.org');
employeeRec.setFieldValue('subsidiary', 3);
employeeRec.setFieldValue('giveAccess', true);
employeeRec.setFieldValue('role', 3);
employeeRec.setFieldValue('password', 'Somepassword1!');
employeeRec.setFieldValue('password2', 'Somepassword1!');
var id = nlapiSubmitRecord(employeeRec);
nlapiLogExecution('DEBUG','done: ' + id + ' employee',id);
var result = new Object();
result.id = id;
return result;
}
When I go to the web interface and pull up the employee record, the "Access" tab does not have the giveAccess checkbox checked. And trying to login as the new user does not work. Is there a trick other than employeeRec.setFieldValue to set these values?
Not sure if you ever found the answer or not... I know this is an old post.
I was able to update the user roles programmatically Below is the Mass Update Script I'm using. It can show you how to add a role to a user with SuiteScript.
function massUpdate(recType,recID){
var roleID=1234;
var empRec=nlapiLoadRecord(recType,recID);
var roleCount=empRec.getLineItemCount('roles');
var thiRole=empRec.setLineItemValue('roles','selectedrole',roleCount+1,roleID);
var submitRec=nlapiSubmitRecord(empRec);
}
The issue you had was that you were setting a field value, instead of a sublist field value. Hope that helps.
Checking the box by itself, whether through the UI or scripting, isn't enough to grant access. You also need to specify a role for the user to use.
First glance through the scriptable records browser, it doesn't seem that roles are scriptable except as search filters and search columns.
https://system.netsuite.com/help/helpcenter/en_US/RecordsBrowser/2013_2/Records/employee.html
Here is a working example in suitescrpit 2.0 to add a role on an employee.
/**
* #NApiVersion 2.x
* #NScriptType UserEventScript
* #NModuleScope SameAccount
*/
define(['N/record'],
/**
* #param {record} record
*/
function(record) {
function beforeSubmit(scriptContext) {
log.debug('in the script');
scriptContext.newRecord.setSublistValue({
sublistId: 'roles',//'jobresources
fieldId: 'selectedrole',//'jobresource',
line: 3,
value: 4
});
}
return {
beforeSubmit: beforeSubmit,
};
});

Resources