admin管理员组

文章数量:1290957

I am trying to make a triger to fire a function on a specific date in the future. I am using the .atDate method, but I want to use a cell from the sheet as a reference.

My code is:

`function createTimeTrigger() {
  ScriptApp.newTrigger("AdditionalSlots")
  .timeBased()
  .atDate(2025, 02, 12)
  .create();
}`

... and it works fine. My problem is that I wand to set the date (2025, 02, 12), from a cell of the sheet and after that to run the code. Is there a solution to grab the date from the cell and used it in the code? Thank you!

I am trying to make a triger to fire a function on a specific date in the future. I am using the .atDate method, but I want to use a cell from the sheet as a reference.

My code is:

`function createTimeTrigger() {
  ScriptApp.newTrigger("AdditionalSlots")
  .timeBased()
  .atDate(2025, 02, 12)
  .create();
}`

... and it works fine. My problem is that I wand to set the date (2025, 02, 12), from a cell of the sheet and after that to run the code. Is there a solution to grab the date from the cell and used it in the code? Thank you!

Share Improve this question edited Feb 14 at 20:16 leylou 5641 silver badge10 bronze badges asked Feb 13 at 15:41 Konstantinos RizopoulosKonstantinos Rizopoulos 31 silver badge1 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

You may try:

function createTimeTrigger() {
  ScriptApp.newTrigger("AdditionalSlots")
    .timeBased()
    .at(SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("A1").getValue())
    .create();
}

This gets the date in A1 and creates a trigger for that period.

REFERENCE

  • at(date)

本文标签: dateTime trigger atDate using a cell as a referenceStack Overflow