When the user check the checkbox, the last modified date appears in the next column, this is my sheet.
But the add timestamp function it's not working when I try on phone and tablet.
I know some triggers don't work with G sheets in Android like active or getactive. Please help to me, how can I fix this problem. Thank you!
Here is the code (from internetgeeks...):
Screenshot of the script:
welcome, it would be fine to get the code in text. Nevertheless, this one works fine on my android phone
function onEdit(event){
var col = 1; // colonne A
var feuille = "Feuille 1";
var f = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if ((r.getColumn() == col) && (f.getName() == feuille) && (r.getRow() > 2)){
var d = Utilities.formatDate(new Date(), "GMT+1", "EEE dd/MM/yyyy HH:mm") // H24
r.offset(0,1).setValue(d);
}
}
Related
I'm looking for a code I can use in google sheets.
I need to get a notification when a cell changes in a specific column and get it through email or Slack.
Can someone please help me?
I'm currently using
function onSpeEdit(e) {
var sh = e.source.getActiveSheet();
var rng = e.source.getActiveRange();
var col = 1
if (sh.getName() == 'mySheet' && rng.getColumn() == col) {
MailApp.sendEmail(
'yourEmail#gmail.com',
`Change Notification`,
`Change in ${rng.getA1Notation()} old value "${e.oldValue}" new value "${e.value}" `);
}
}
Try
function onSpeEdit(e) {
var sh = e.source.getActiveSheet();
var rng = e.source.getActiveRange();
var col = 1
if (rng.getColumn() == col) {
MailApp.sendEmail(
'yourEmail#gmail.com',
`Change Notification`,
`Change in ${rng.getA1Notation()} of ${sh.getName()} old value "${e.oldValue}" new value "${e.value}" `);
}
}
change name of sheet, column and email address
you will need to define an installable trigger in order to use services that requires authorization.
Installable Triggers
edit : il you want to add another information, i.e. from column B, try to replace the sentence by
`Hey, the title ${sh.getRange('B'+rng.getRow()).getValue()} from sheet ${sh.getName()} changed. Before it has the number ${e.oldValue} now is ${e.value}.`
I am running the following script as its own .gs file
/**
* TITLE:
* Hide a row if a value is inputted.
*/
//**GLOBALS**
// Sheet the data is on.
var SHEET = "Norm Adam";
// The value that will cause the row to hide.
var VALUE = "Yes";
// The column we will be using
var COLUMN_NUMBER = 11
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeSheet = ss.getActiveSheet();
//Ensure on correct sheet.
if(SHEET == activeSheet.getName()){
var cell = ss.getActiveCell()
var cellValue = cell.getValue();
//Ensure we are looking at the correct column.
if(cell.getColumn() == COLUMN_NUMBER){
//If the cell matched the value we require,hide the row.
if(cellValue == VALUE){
activeSheet.hideRow(cell);
};
};
};
}
It works fine on a computer browser but on iOS device it doesn't work through the google sheets app and I actually can't even get the editable through safari. I read that only the onEdit function will work on a mobile device so I figured this should work. Is there another piece to this puzzle?
Thanks
Mike
(credit for script creation goes to: https://yagisanatode.com/2018/05/26/how-to-hide-a-row-based-on-a-cell-value-in-google-sheets-with-filter-or-google-apps-script/ )
Script V2:
I commented below on this still not working in iOS. I figured the simpler it was the more likely to work?
function onEdit(e) {
if (e.range.getColumn() == 11 && e.value == 'Yes') {
e.range.getSheet().hideRows(e.range.getRow());
}
}
getActive calls, especially ss.getActiveCell() should be avoided on mobile apps. Consider alternatives like e.range to get the edited range from event objects.
I wonder if anyone can help me with the following google script? I just begin to work on some google script and help my colleagues to track the production of his work.
Here is the field is explained below.
Column 9 = Status (Dropdown list: Pending, In-progress, Done)
Column 11 = Send Date
Column 13 = Start Date
Column 14 = End Date
How I want the script work
Example:
When Column 9 (dropdown list) value = "Pending" then auto fill the current
date to Column 11.
When Column 9 (dropdown list) value = "In-progress" then auto fill
the current date to Column 13.
When Column 9 (dropdown list) value = "End Date" then auto fill the current
date to Column 14.
The code I am working on to get when the status is "In-Progress".
I know I am wrong about this part. -> [s.getValue() !== 'In-progress']
But I am not sure where or how to put the certain text that I am looking for in here.
function onEdit(e) {
var s = e.source.getActiveSheet(),
cols = [9],
colStamp = 13,
ind = cols.indexOf(e.range.columnStart)
if (s.getName() !== 'Lab Cases Tracker' || s.getValue() !== 'In-progress' || ind == -1) return;
e.range.offset(0, parseInt(colStamp - cols[ind]))
.setValue(e.value ? new Date() : null);
}
Thank you so much!
This should do it:
function onEdit(e) {
var ss=SpreadsheetApp.getActiveSpreadsheet()
var s1=ss.getActiveSheet()
var s = e.source.getSheetName()
var col=e.range.getColumn()
var r=e.range.getRow()
var val=e.value
var curDate = Utilities.formatDate(new Date(), "GMT+1", "MM/dd/yyyy")
if(s=="Lab Cases Tracker" && col==9){
if(val=="Pending"){
s1.getRange(r,11,1,1).setValue(curDate);
}
else if(val=="In-progress"){
s1.getRange(r,13,1,1).setValue(curDate);
}
else if(val=="End Date"){
s1.getRange(r,14,1,1).setValue(curDate);
}
else{return}
}}
I have a google spreadsheet that i have one last problem i cant seem to solve.
i added a button to this script, and when i press the button it triggers the AddClient function.
How can i make the script below loop down all rows in column 3 searching for the yes value, when it finds it, copy the row below it to sheet "client" and then stop?
function AddClient(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "SETUP" && r.getColumn() == 3 && r.getValue() == "yes") {
var row = r.getRow() + 1; // Add 1 to the active row
var targetSheet = ss.getSheetByName("client");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 2, 1, 4).copyTo(target, {contentsOnly:true}); //Only selecting column 2, then the following 4 columns
}
}
Edit*
Example document:
https://docs.google.com/spreadsheets/d/1DFbAp0IN8_UFv9u8kWiZBTxDogj4e7FnuAPzC0grDw0/edit?usp=sharing
Any help greatly appreciated!
Cheers,
Reiel
Since you have a static form the position of the informatin to be copied will not change
Since we know we want to copy over the data we won't need to do any validation of where we are so all of that stuff can go
Sheets have an appendRow method that take care of the bookkeeping involved with finding the last row
This allows us to simplify the script to the following:
function AddClient() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var data = ss.getSheetByName("SETUP").getRange(25, 2, 1, 4).getValues()[0];
ss.getSheetByName("client").appendRow(data);
}
Edit:
To remove duplicates you could do the following:
function AddClient() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var data = ss.getSheetByName("SETUP").getRange(25, 2, 1, 4).getValues()[0];
var clients = ss.getSheetByName("client").getDataRange().getValues();
if (!clients.filter(function(row) {return data.join("|") === row.join("|");})) {
ss.getSheetByName("client").appendRow(data);
}
}
Note that for the particular example there are some problems because the leading zero gets cut off. Sheets is a bit weird and sometimes tries to force the format to be a number even when you set the cells' formats to Text...
I am using Google Spreadsheets and what I am trying to do is update the cells that contain a timestamp in the Time last Updated column each time I update a cell in the same row.
Is there any way I can achieve that?
Thanks in advance,
not tested but something like this should work. Since you didn't provide any details, you will have to change some variables according to your needs.
function onEdit(e) {
var startCol = 2,
endCol = 10,
tsCol = 11, //this is the column where the timestamp will appear
startRow = 2,
sheetName = 'Sheet1', //this is the name of the sheet you want the script to work on.
curSheet = e.source.getActiveSheet();
//exit script when edits are made another sheet, or in the first row, or before col 2 or after col 10
if (curSheet.getName() !== sheetName || e.range.columnStart < startCol || e.range.columStart > endCol || e.range.rowStart < startRow) return;
curSheet.getRange(e.range.rowStart, tsCol)
.setValue(new Date());
}