I have an ArrayCollection that I'd like to sort by date and then time (in case there's two items with the same date). I've got it sorting by date fine (YYYY/MM/DD) but I can't figure out the time bit, time is in 24 hour format so the code would be basically the same as for the date.
This is the code I used for the date sorting, it works fine.
import mx.collections.SortField;
import mx.collections.Sort;
private function sort():void
{
var dataSortField:SortField = new SortField();
dataSortField.name = "date";
var arrayDataSort:Sort = new Sort();
arrayDataSort.fields = [dataSortField];
reminderXMLArray.sort = arrayDataSort;
reminderXMLArray.refresh();
}
You can use this code to sort by date and time:
private function sort():void
{
var dataSortField:SortField = new SortField();
dataSortField.name = "date";
dataSortField.compareFunction = function (a:Object, b:Object) : int {
var na:Number = a.date.getTime();
var nb:Number = b.date.getTime();
if (na < nb)
return -1;
if (na > nb)
return 1;
return 0;
};
var arrayDataSort:Sort = new Sort();
arrayDataSort.fields = [dataSortField];
reminderXMLArray.sort = arrayDataSort;
reminderXMLArray.refresh();
}
As there are two separate fields that you want to sort on you can just use the Sort object's fields Array to add two sort fields:
var sort:Sort = new Sort();
var fields:Array = [ new SortField("date"), new SortField("time") ];
sort.fields = sort;
Related
I am including the script ( below), the trigger, the sample of the spreadsheet, image of the start and end time formatting and the error(below)...
When I run the createCalendarEvent script manually...no issues..it is when i try to automate the script by creating an event trigger for on form submit that I get the following error:
Error Exception: Event start time must be before event end time.
at createCalendarEvent(create event:26:16)
function createCalendarEvent() {
var sheet = SpreadsheetApp.getActiveSheet();
var calendar =
CalendarApp.getCalendarById("c_71lju3i096qeqsg69bd7togo9g#group.calendar.google.com");
var startRow = 2; // First row of data to process - 2 exempts my header row
var numRows = sheet.getLastRow(); // Number of rows to process
var numColumns = sheet.getLastColumn();
var dataRange = sheet.getRange(startRow, 1, numRows-1, numColumns);
var data = dataRange.getValues();
var complete = "Done";
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var startTime = new Date(row[0]); //start Time
var endTime = new Date(row[1]); //end Time
var title = row[2]; //Item Title
var option = row[3]; //event option
var location = row[4]; //location
var eventID = row[6]; //event marked Done
if (eventID != complete) {
var currentCell = sheet.getRange(startRow + i, numColumns);
calendar.createEvent(title, startTime, endTime, {description: option + '\r' , location:
location});
currentCell.setValue(complete);
}
}
}
I have edited the original script and included the trigger just in the script itself ( By passing the automated trigger creation)...this way worked....1 time!..now i get the following error.
Exception: Action not allowed setUpTrigger # create event.gs5
function setUpTrigger() {
ScriptApp.newTrigger('createCalendarEvent')
.forForm('1FAIpQLScQvxc8EUSjGvrrVc6-QE3LwNZOytetIrfOVX-RKrJwS8_ALw')
.onFormSubmit()
.create();
}
function createCalendarEvent() {
var sheet = SpreadsheetApp.getActiveSheet();
var calendar = CalendarApp.getCalendarById("c_71lju3i096qeqsg69bd7togo9g#group.calendar.google.com");
var startRow = 2; // First row of data to process - 2 exempts my
header row
var numRows = sheet.getLastRow(); // Number of rows to process
var numColumns = sheet.getLastColumn();
var dataRange = sheet.getRange(startRow, 1, numRows-1, numColumns);
var data = dataRange.getValues();
var complete = "Done";
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var startTime = new Date(row[0]); //start Time
var endTime = new Date(row[1]); //end Time
var title = row[2]; //Item Title
var option = row[3]; //event option
var location = row[4]; //location
var eventID = row[6]; //event marked Done
if (eventID != complete) {
var currentCell = sheet.getRange(startRow + i, numColumns);
calendar.createEvent(title, startTime, endTime, {description:
option + '\r' , location: location});
currentCell.setValue(complete);
}
}
}
The error message is pretty self explanatory.
Error Exception: Event start time must be before event end time
Check the values you are sending for start and end time. Make sure that the event does not end before it starts.
var startTime = new Date(row[0]); //start Time
var endTime = new Date(row[1]); //end Time
I am trying to get a spreadsheet to update a calendar on my Google account, but I am struggling to get the if condition on the code below to work. When I run inseritoNelCal the debug says that it is unspecified even though the spreadsheet has actually data in each row/column.
var IN_CAL = new String('INSERITO');
function dallaTabellaAlCalendario() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 3);
// 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 title = row[0]; // First column
var startTime = new Date(row[1]); // 2nd column
var endTime = new Date(row[02]); // 3rd column
var description = row[3]; // 4th column
var location = row[4]; // 5th column
var guests = row[5]; // 6th column
var inseritoNelCal = row[6]; // 7th column
}
if (inseritoNelCal != IN_CAL){
var calendar CalendarApp.getCalendarById("mycalendarID").createEvent(title, startTime, endTime, {Descrizione: description, Luogo: location, Allievi: guests, Inserito: inseritoNelCal });
sheet.getRange(startRow, 7).setValue(IN_CAL);
}
}
I have used linq to store data, below is the code:
var result = (dynamic)null;
var serviceData = (dynamic)null;
var userData = (dynamic)null;
/****Linq 1*****/
serviceData= dtPasscode.AsEnumerable().Select(m => new
{
ACCOUNT_ID = intAccountId,
SUB_ACC_ID = m.Field<string>("ACCOUNT_ID_ALIAS")
});
/**Linq 2**/
userData = DisplyCustomerDetails(Convert.ToInt64(strSubAccountID));
result = serviceData.Concat(userData);
And another linq through function:
/**Function**/
System.Data.EnumerableRowCollection DisplyCustomerDetails(Int64 intAccountId)
{
var result = (dynamic)null;
/** Data Display if no service avaiable **/
IAccount_BL objAccount_BL = new Account_BL();
Customer objCustomer = new Customer();
DataTable dtCustomer = null;
int intErrorCount = 0;
objCustomer.Account_Id = Convert.ToInt64(intAccountId);
dtCustomer = objAccount_BL.GetCustomerDetails(objCustomer, ref intErrorCount);
objAccount_BL = null;
objCustomer = null;
if (intErrorCount == 0)
{
if (dtCustomer != null)
{
if (dtCustomer.Rows.Count > 0)
{
result = dtCustomer.AsEnumerable().Select(m => new
{
ACCOUNT_ID = intAccountId,
SUB_ACC_ID = m.Field<string>("ACCOUNT_ID_ALIAS")
});
}
}
}
return result;
}
I wanted to join both the result of Linq1 & Linq2, I tired Concat & Union, getting below error
'System.Data.EnumerableRowCollection<<>f__AnonymousTypea>' does not contain a definition for 'Concat'
To Concat both enumerables must of the same class; you cannot use anonymous classes. Define a class that has the two fields and change the code to Select them.
Also, don't use ... = (dynamic) null; just assign the variable directly
var serviceData= dtPasscode ...
var userData = DisplyCustomerDetails ...
var result = serviceData.Concat(userData);
linedataColl is an AC that contains 100+ of rows extract from CSV, I wish to add item into SuperDataCollection object by object but the only problem was I'm unable to see any data display in "S" which is a datagrid. What wrong with my code?
var superDataCollection:ArrayCollection = new ArrayCollection();
var dc:ArrayCollection = new ArrayCollection();
var di:Object = new Object();
for(var aa:int=0; aa<5;aa++){
di.username = linedataColl[aa].username;
di.email = linedataColl[aa].email;
dc.addItem(di);
superDataCollection.addItem(dc);
}
s.dataProvider = dc;
For my datagrid:
var columns:Array = [];
var myDataGridColumn:DataGridColumn = new DataGridColumn("id");
myDataGridColumn.headerText = "ID";
myDataGridColumn.width = 40;
columns.push(myDataGridColumn);
... // so on for other column
dg1.columns = columns;
I Found Two thing wrong in your code
1) Declare di in For loop, new instance for each iteration
for(var aa:int=0; aa<5;aa++){
var di:Object = new Object();
2) You are not defining proper dataField for DataGridColumn, although you are passing id in constructor, but i didn't find it in upper code you share,it could be
di.id = aa
or
myDataGridColumn.headerText = "ID";
myDataGridColumn.width = 40;
myDataGridColumn.dataField = "username";
Hopes that helps
I'm trying to get the current date time in Flex/AIR?
To get the current date time, just create a new Date object with no values into the constructor, like this:
var CurrentDateTime:Date = new Date();
Formatting it depends on how you want to format it; here is one option:
private function CurrentDateTimeString():String
{
var CurrentDateTime:Date = new Date();
var CurrentDF:DateFormatter = new DateFormatter();
CurrentDF.formatString = "MM/DD/YY LL:NN:SS A"
var DateTimeString:String = CurrentDF.format(CurrentDateTime);
return DateTimeString;
}
currentTime = new Date();
From : http://livedocs.adobe.com/flex/3/html/help.html?content=08_Dates_and_times_5.html
and
http://docs.huihoo.com/flex/4/Date.html
private function CurrentDateTimeString():String
{
var CurrentDateTime:Date = new Date();
var DateString:String = CurrentDateTime.getMonth().toString()+ "/"+CurrentDateTime.getDate().toString() +"/"+CurrentDateTime.getFullYear().toString();
var TimeString:String = CurrentDateTime.getHours().toString()+ ":"+ doubleDigitFormat(CurrentDateTime.getMinutes());
var DateTimeString:String = DateString + " " + TimeString;
return DateTimeString;
}
function doubleDigitFormat(num:uint):String
{
if(num < 10) {
return ("0" + num);
}
return num.toString();
}