I currently have a trigger which updates with a new value every 15 minutes. Unfortunately it updates continuously.
I'd like it to stop between 08:00 and 16:00 for example.
Is there a way to achieve this? Thanks in advance.
Yes there is a way!
What you can do in this situation is to:
Method 1
Create a new trigger which will fire at 08:00 to delete the previous trigger.
To delete a trigger, you can use something similar to this, according to the documentation:
function deleteTrigger(triggerId) {
var allTriggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < allTriggers.length; i++) {
if (allTriggers[i].getUniqueId() === triggerId) {
ScriptApp.deleteTrigger(allTriggers[i]);
break;
}
}
}
Create a new trigger which will fire at 16:00 to create the new trigger which runs every 15 minutes.
Method 2
Customize your trigger in such a way that it triggers only for the specific action you need/want.
Reference
Apps Script Installable Triggers.
Related
I have a table in Google Sheets in the format:
A B C
Day Date inventory demand
Day2 Date2 inventory demand
etc.
Others are required to fill in inventory and demand every day. Thus, it would be helpful if they open the sheet they jump always to the current date. This could be done over HYPERLINK or code. However, as I am informed onOpen works for the editor, however not for viewers. As this is currently the case. When I open the file I jump to the current date, however people viewing and editing the file per link do not.
Could somebody please help me? Thank you.
I also do not understand, why creating a cell that jumps to the current date as an alternative does not work.
I tried various variations of
=HYPERLINK("l i n k&range=B"&MATCH("TODAY",B1:B1500,0),"Jump to today")
or
=HyperLink("LINK&range=B" &Match(Today(),B6:B,1),"JUMP to Today")
// jump to current date
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getRange("B:B");
var values = range.getValues();
var day = 24*3600*1000;
var today = parseInt((new Date().setHours(0,0,0,0))/day);
var ssdate;
for (var i=0; i<values.length; i++) {
try {
ssdate = values[i][0].getTime()/day;
}
catch(e) {
}
if (ssdate && Math.floor(ssdate) == today) {
sheet.setActiveRange(range.offset(i,0,1,1));
break;
}
}
}
try like this:
=HYPERLINK("#gid=0&range=B"&MATCH(TODAY(); B6:B; 0)+5; "zu heute")
I found the options: Edit Triggers
To manually create an installable trigger through a dialog in the script editor, follow these steps:
From the script editor, choose Edit > Current project's triggers.
Click the link that says: No triggers set up. Click here to add one now.
Under Run, select the name of function you want to trigger.
Under Events, select either Time-driven or the Google App that the script is bound to (for example, From spreadsheet).
Select and configure the type of trigger you want to create (for example, an Hour timer that runs Every hour or an On open trigger).
Optionally, click Notifications to configure how and when you are contacted by email if your triggered function fails.
Click Save.
Google Explanation
Is it even possible to have a slide presentation delete a slide base off of a date. For example have the slide expire after a certain date. The purpose is for digital signage. I was just hoping to write a script that deleted a slide.
Please let me know if my question is not clear.
first post #not a programmer...yet
I think you want to do a cron. Cron is time-based job scheduler, to run periodically at fixed times, dates, or intervals.
One sample would be using a time-driven trigger to run a function (delete slide).
The code snippet that I used would be in Apps Script to run using a time driven trigger and code to delete a page in a slide.
function checkslide(){
var origin = Slides.Presentations.get(originSlideID).slides;
Logger.log(origin[1])
var slide = SlidesApp.openById(targetSlideID).getSlides();
//remove all slide other than first page
slide.splice(targetSlideID - 1, 1);
for (var i in slide) {
slide[i].remove();
}
//remove a specify depending on condition where j is the slide to be removed
for (i = 0; i < slide.length; i++) {
if(i == j){
slide[i].remove();
}
}
}
References:
https://developers.google.com/slides/samples/writing#delete_a_page_or_page_element
https://developers.google.com/apps-script/guides/triggers/installable
I wrote some scripts using the script editor to automate some google spread-sheet tasks.
I would like to do a few things after the user interacts with my users sheets, .e.g update some background sheets that start with _.
I wrote the following:
function onEdit(e){
var range = e.range;
if (e.source.getActiveSheet().getName()[0]!='_'){
//It is an user edit!
UpdateOtherHiddenTables()
}
};
My problem is that UpdateOtherHiddenTables() takes quite a while, like 2 mins, and it is triggered on any user edit so it is not ideal.
How would you make sure that after a user has interacted with a sheet, that UpdateOtherHiddenTables() is called, but not too often?
I would use Script properties in combination with a timed trigger. The on-Edit trigger only records the fact that the Spreadsheet was edited:
function recordEdit() {
var sp = PropertiesService.getScriptProperties();
sp.setProperty("edited", "yes");
}
This function needs to be run by an installable trigger, simple onEdit won't provide the authorization necessary to modify script properties.
The UpdateOtherHiddenTables function is set to run every 10 minutes, or every hour, or whatever interval you want. It checks whether a refresh is needed.
function UpdateOtherHiddenTables() {
var sp = PropertiesService.getScriptProperties();
if (sp.getProperty("edited") == "yes") {
// update stuff
sp.setProperty("edited", "no");
}
}
By the way: onEdit is only triggered by user edits. A script changing the values in a spreadsheet will not fire that trigger.
I'm using string values instead of Boolean, because Properties stringifies everything. Storing false gets you back the string "false", which is truthy...
I'm trying to have a timestamp appear in a column whenever data is added to a sheet. I've had some success with the following script:
function onEdit(e) {
var colToWatch = 2, colToStamp = 1;
if (e.range.columnStart !== colToWatch) return;
var writeVal = e.value ? new Date() : '';
e.source.getActiveSheet()
.getRange(e.range.rowStart, colToStamp)
.setValue(writeVal);
}
My issue is, every time the text in col 2 is edited, the timestamp changes to the current time.
My hope it to have a timestamp that shows when the text was originally added (so it can be organized by that date in another sheet). Other people will have access to this sheet and may change something by accident and cause changes in the sheet organized by date.
I'm new to scripting, is it possible to have an onEdit only run the first time data is added? It seems like onChange() might be able to help me, but I haven't been able to find anything.
Basically you want to terminate if the timestamp cell is already filled.
if (e.source
.getActiveSheet()
.getRange(e.range.rowStart, colToStamp)
.getValue()) {
return;
}
I have a job scheduled in Application_start event using quartz.net, the trigger is fired every 1 min given by the variable repeatDurationTestData = "0 0/1 * * * ?";
The triggering starts when I first open the site, But stops after some random time when I close the browser and starts again when I open the site. Following is the code
IMyJob testData = new SynchronizeTestData();
IJobDetail jobTestData = new JobDetailImpl("Job", "Group", testData.GetType());
ICronTrigger triggerTestData = new CronTriggerImpl("Trigger", "Group", repeatDurationTestData);
_scheduler.ScheduleJob(jobTestData, triggerTestData);
DateTimeOffset? nextFireTime = triggerTestData.GetNextFireTimeUtc();
What Am i doing wrong here, Is this because of some misfire. Please suggest.
Thanks
At First I would use a simple trigger in this case as it takes a repeat interval and seems to fit better than the cron trigger would (from lesson 5 quartz.net website) :
SimpleTrigger trigger2 = new SimpleTrigger("myTrigger",
null,
DateTime.UtcNow,
null,
SimpleTrigger.RepeatIndefinitely,
TimeSpan.FromSeconds(60));
I would also recommend you don't put the quartz scheduler within the website. the main purpose of a job system is to work independently of anyother system so it generally fits naturally into a windows service. By putting it as part of the website you arn't guaranteed its going to keep going. If you loose the app pool or it restarts, you wont get a reliable result.
There is an example with the quartz.net download.
hope that helps.