On Saturday, August 9, 2014 12:57:29 AM UTC-4, Matthew Mentrup wrote:
>
> Hey, I'm trying to make a very very simple google script to try some stuff
> out but I don't understand why it isn't working because the error it gives
> me in my email shouldn't even be happening.
> Here the error:
>
> Details:
> Start FunctionError MessageTriggerEnd8/9/14 12:53 AM convertToDate
> TypeError: Cannot find function search in object [object Object]. (line
> 28, file "Code") edit8/9/14 12:53 AM
> Here my code:
>
> function myFunction() {
>>
>> }
>>
>> function onEdit(e) {
>> var firstTime = "Not Entered";
>> var secondTime = "Not Entered";
>> var doc = SpreadsheetApp.getActiveSheet();
>> var r = e.source.getActiveRange();
>> var currentCol = r.getColumn();
>> var currentRow = r.getRow();
>> var cellData = r.getValue()
>> var ui = SpreadsheetApp.getUi()
>> if(cellData.indexOf("-") > -1) {
>> var dateSplit = cellData.split("-");
>> firstTime = convertToDate(dateSplit[0]);
>> secondTime = convertToDate(dateSplit[1]);
>> ui.alert(firstTime);
>> }
>>
>> ui.alert(currentCol+":"+currentRow+":"+cellData+":"+firstTime+":"+secondTime);
>> var dateCell = doc.getRange(2, currentCol);
>> dateCell = dateCell.getCell(1,1);
>> ui.alert(dateCell.getValue());
>>
>> }
>>
>> function convertToDate(x) {
>> if(x.search("AM") > -1) {
>> x = x.replace("AM","");
>> x = parseInt(x);
>> }
>> else if(x.search("PM") > -1) {
>> x = x.replace("PM","");
>> x = parseInt(x)+parseInt(12);
>> }
>> else {
>> x = "Invalid Format!";
>> }
>> return x;
>>
>> }
>>
>
Also while I am here maybe someone could help me make an easier way to do
this maybe a pre defined formula on the sheet. Say I got A1,A2, and A3 for
cells. A4 is to display the total amount of hours work.
Such as
A1 = 12:00PM-5:00PM
A2 = 2:00PM-8:00PM
A3 = 8:00AM-4:00PM
Therefore A4 should display 19 Hours
I would use =SUM(DATEDIFF( but the issue is The two things variable I would
use would be in the same table cell. So anyone know an easy way or would I
need to make a script? Also does google script work with javascript? I ask
because any functions I try to use from the google script API keeps coming
up as "Invalid" or "Undefined" functions.
--
You received this message because you are subscribed to the Google Groups
"Google Spreadsheets API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.