Scripts, scripts, scripts!

The following produces a date with timestamp

var time = new Date();

What could I use to create just a date i.e. 2020/1/18 (Without time stamp) ?

Here you go…

function get_today() {
  var date = new Date();
  var str =
      date.getFullYear() + "/" +
      (date.getMonth() + 1) + "/" +
      date.getDate();
  return str;
}

Called as:

function moo() {
  console.log("Today is %s", get_today());
}

Produces:

7:48:48 AM Notice Execution started
7:48:46 AM Info Today is 2021/1/19
7:48:49 AM Notice Execution completed

PS. Why you should always use yyyy-mm-dd for dates.

4 Likes

Thank you @Darren_Murphy . You are a gentleman and a scholar.

2 Likes

@ehdubya @Wiz.Wazeer - I found a bug in this script. I fixed it, see the edit in my original post.

2 Likes

Im going to be testing this on the glide countdown timer…I am sure this could help me unlock something (fingers crossed)!

Just out of curiosity, what is the problem that you’re hoping this might solve?

Thank you! I’l give it a go now

Currently its a combination of numbers and texts. Yours generates numbers only. Glide instantly recognizes that and therefore I can play around with duration cell in the sheet. At present the moment you press pause it all disappears. With yours I want to see if I can keep it in the cell. Then I can truly play around with the countdown timer.

Not sure I understand, but okay…
Let me know if I can help in any way.

1 Like

Its just me and my weird ways …But I know you will be able to assist…If you can’t then I have no hope lol

1 Like

@Wiz.Wazeer sorry man, I haven’t been on a ton this past week. What are you trying to do in scripts again?

1 Like

Solved for now! I am working on something …I have managed to create a dynamic calendar using sheet formulas. when x types in 1-12, it will show the corresponding month and all slots for that particular month. I was looking for a script to send bulk emails to several contract workers (cleaning industry)…on selection. Found the script. But if I get stuck I will let you guys know.

Thanks and take it easy on yourself (saw you on CNN with a capitol C, i think–you know what I mean :rofl:)

1 Like

It would be cool if we can send a email based on event, Like reminder a day before then 1 Hour before. Or in the morning everyday at 9:00 If date is today. you get the point.

Example can be, IF(Job Completed) = Never Remind me.
else, If Start is (Today) Then Reminder & set col + 1 ( for first reminder) , then Repeat hour before, So on.
we can even add to script. If End is past. (Was the job Done col) will be checked. If a user unchecked it will reset and resend email. Any thoutes about this?

2 Likes

Yes, all possible and fairly straight forward.

  • Scenario 1: Send an email on a regular schedule (once per day, per hour, etc)

    • To do this I will use a time based trigger to setup the schedule
    • When the trigger fires, it will call some code that “does stuff”
    • If the result of that “stuff” is that an email needs to be sent, then call an Integromat webhook
    • Integromat does the rest
  • Scenario 2: Send an email as a result of an event - ie. when something significant changes

    • In this case, an onChange() trigger is appropriate. This ensures that the event is detected as soon as possible after it happens
    • The rest is the same as in Scenario 1.

I use both scenarios. Horses for courses :slightly_smiling_face:

2 Likes

OK need help convert this to

  1. Instead of HardCoded Col, Lets change it to read headers Instead.

  2. Email Send email to 10 Col, (Allow to read 10 Col collect all emails and send it that way. )

  3. Allow 1 header (Col) To trigger upon Edit (For Glide.)

  4. Allow a header (col) If true Continue Script. For user to select if they want to be notified in advance.

  5. Add If start TimeStamp ( Something like we discussed. Above, I will add hourly trigger. )

  6. Col with time stamp, For some reasons also shows GMT-5 Easter Stander time text. Lets avoid that By stripping it?

    function sendEmail() { 
    var name         = SpreadsheetApp.getActiveSheet().getName();
    var row          = SpreadsheetApp.getActiveSheet().getActiveCell().getRow(); // Active Row
    var columnactive = SpreadsheetApp.getActiveSheet().getActiveCell().getColumn(); 
    var sheetname    = "Quotes"                          // replace sheet name with your sheet name
    var sheetid      = "Somthing"         // replace sheet ID with your sheet ID 
    
    if( name == sheetname &&  columnactive == 42  ) { //checks that we're on the correct sheet, replace column number if need it
      var sheet = SpreadsheetApp.openById(sheetid).getSheetByName(sheetname);  
               
     //email notification 
     //getRange(row, column, numRows, numColumns)  // Should work to collect emails? I guess not. 
     var email =  sheet.getRange(row,32,1,10).getValue()     // replace renge parameters if need it
     
     var Title = "Today From Calendar "
     var job_Type  =  sheet.getRange(row,8,1,1).getValue()   
     var The_Job  =  sheet.getRange(row,9,1,1).getValue()  
     var Note  =  sheet.getRange(row,10,1,1).getValue()   
     var Stats  =  sheet.getRange(row,11,1,1).getValue()  
     var Remarks  =  sheet.getRange(row,12,1,1).getValue() 
     var description  =  sheet.getRange(row,2,1,1).getValue()   
     var Client  =  sheet.getRange(row,3,1,1).getValue()   
     var Address  =  sheet.getRange(row,4,1,1).getValue()  
     var Phone  =  sheet.getRange(row,5,1,1).getValue()  
     var Manager_Phone  =  sheet.getRange(row,6,1,1).getValue()  
     var UserEmail  =  sheet.getRange(row,7,1,1).getValue()  
     var TimeStamp  =  sheet.getRange(row,29,1,1).getValue()  
     var Start  =  sheet.getRange(row,30,1,1).getValue()  
     var End  =  sheet.getRange(row,31,1,1).getValue()  
    
    MailApp.sendEmail({
    to: email,    
    subject: Title, 
    body:  "\n\Name: "+Client+
    "\n\Phone: "+Phone+     
    "\n\Manager: "+Manager_Phone+    
    "\n\UserEmail: "+UserEmail+   
    "\n\nAddress: "+ Address +  
    "\n\Stats: "+Stats+  
    "\n\The_Job: "+The_Job+    
    "\n\job_Type: "+job_Type+     
    "\n\description: "+description+ 
    "\n\Note: "+Note+ 
    "\n\Remarks: "+Remarks+
    "\n\nStart: "+Start+
    "\n\End: "+End+    
    "\n\nTimeStamp: "+TimeStamp  
    });           
    }
    }
    

@ThinhDinh @Darren_Murphy

@Darren_Murphy I would take your script that you have and try to work with it first and let you know if i can do it on my own.

@abe.sherman this is a classic example of why I don’t use App Scripts to send emails. Having all those hard-coded references to specific columns is way too fragile and subject to breakage. It’s also going to be really slow because of the multiple getRange() calls.

A much better approach (IMO, as I said in my earlier post) is to use a trigger to fire a webhook to Integromat, and then let Integromat do all the heavy lifting for you.

Is there are reason why you don’t want to use something like Integromat or Zapier?

For this particular app i am not paying for yet besides the extra edits. For my other app. I can differently try using it in the future as i am paying for it. The webhook cost money and i dont have it for this app set up, Plus it wont give me everything i want to do with the webhook, Will it?

Even thou its planned in the very long run to pay for it. as of now. i dont have much clients using it besides a handfull. When the app is complete and i can intruduse it. then things will be different.

Integromat give you 1000 operations per month for free.

I’ll have a closer look later when I have a bit more free time. In the meantime, can you provide a sheet with some sample data?

Same one we used last time

Hi there
I look for an example script: need to compare two tables and if it finds a match, copy the row to the third table.
Now I have it:
function Alarm ()
{
var sheet = SpreadsheetApp.openById (“id”);
var Data1 = sheet.getSheetByName (‘Feed’);
var Data2 = sheet.getSheetByName (‘Alarm-list’);
var Data3 = sheet.getSheetByName (‘Notifications’);
}
Already suggested (thanks @ThinhDinh ) that it should be the expression “When I add to table A, if the input info matches a row in table B, write both to table A and table C, and show an in-app notification. If no, only write to table A.
Same for table B, if the input info matches a row in table A, write both to table B and table C, and show a notification. If no, only write to table B. "
But how to express it in the code - I don’t know.
Help, please.

1 Like