I would like to be able to achieve this on my google sheet.
Requirements.
IF Column B is not equal to the word " Pending ". Delete that row
IF the row gets updated and the content on Column B for that row gets updated AND IS NOT EQUAL to the wor " Pending". Delete that row as well.
So I would like to achieve auto row delete for existing and future updates on the sheet.
Thank you!
Just change the name of the sheet in the getSheetByName method to whatever you want. Deleting rows goes a lot easier if you start from the bottom. This function will do the deleting. The remaining issue is what's going to initiate the process. Perhaps a timed trigger?
function delIfBPending()
{
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sht=ss.getSheetByName('delIfPending');//Change this name as needed
var rng=sht.getDataRange();
var rngA=rng.getValues();
for(var i=rngA.length-1;i>-1;i--)//this limit is dependent upon whether or not you have a header row.
{
if(rngA[i][1]=='Pending')
{
sht.deleteRow(i+1);
}
}
}
Related
I don't know anything about Google Scripts. All the scripts mentioned here under including the formulas have been researched on internet and improvised gradually. I need help of experts like you to achieve my outcomes. I am a beginner, hence please write your answer which I can understand. It would be great if you improve my script / formulas with brief explanation in simple language.
I have two sheets:
1) Form Response Sheet (linked to form)
2) DataBnak Sheet (importing form response data via query: =query('Form Responses 3'!$A:$BH,"",1)
I am using ArrayFormula in "DataBank" Sheet to create a unique text report based on values pulled "Form Responses". This report needs to be emailed to each respondent upon form submit. the report is pulled in CH column thru (ArrayFormula), and once the mail is sent, I am marking "1" in CM column so to ensure duplicate mails are not sent every time the script runs.
=ArrayFormula(IF(ROW($B:$B)=1,"Breif Report",IF(ISBLANK($B:$B),"",if(NOT(ISBLANK($CM:$CM)),"",iferror(vlookup(BU:BU&BV:BV&BW:BW&BX:BX,BriefProfile!$E:$F,2,0),"")))))
Formula Explanation: where Cell in B column is not blank, and where cell in CM column is not blank (mail not sent), then bring the pre-written text based on the look-up value within columns (BU,BV,BW,BX).
What works correct:
1) The ArrayFormula works perfect (it pulls correct pre-written text)
2) Mail Script Works perfect (it sends to mails to those who have not been sent mail earlier)
What does not work:
1) The text report picked for a respondent is same for all respondents. When I remove ArrayFormula and ValuePaste the text report instead of calling it thru the formula mentioned above, then mail script picks up the correct unique report for each respondent and sends mail.
My mail script is mentioned below:
function sendEmails() { // Sends non-duplicate emails with data from the current spreadsheet.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DataBank");
var Avals = sheet.getRange("A1:A").getValues(); // helps getting last fillled row^
var Alast = Avals.filter(String).length; // helps getting last fillled row^
var startRow = 2; // First row of data to process
var numRows = Alast-1; // Number of rows to process - last filled row^
var dataRange = sheet.getRange(startRow, 1, numRows, 91); // Fetch the range of cells A2:B3 //.getrange(row,column,numRows,numColumns) numColumns should equal to max column number where data process is required.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[1]; // second column, actual column minus one
var message = row[85]; // 85th column, actual column minus one
var emailSent = row[90]; // 90th column, actual column minus one
if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
var subject = row[84] //'Sending emails from a Spreadsheet';
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 91).setValue(EMAIL_SENT);
Utilities.sleep(120000); // keeps the script waiting untill the sheet gets updated values from "ArrayFormula"
}
SpreadsheetApp.flush(); // Make sure the cell is updated right away in case the script is interrupted
}
}
Can you review my mail script and help me improve it so that it picks up correct unique report?
I just solved it. declaring var data = dataRange.getValues(); within the for loop solved my problem. I found the solution just now Thank you all!.
by declaring the variable before the for loop, I was actually storing the static data and the same was used in each iterations. When I declared the variable within for loop, the data started changing at each iteration.
My code is a simple form with 3 input fields. Once the user fills them all in and presses the button it will add a row to the table with the input data aswell as an index number. Like this:
https://imgur.com/g5ToOpF
im trying to give each row in a table an index number that is correct with the amount of rows inserted. This works but now I want it to update the index number when I remove one of the rows from the table.
The following function is triggered when the customer fills in an input field with the desired index number that they want to delete and then press a button.
function removeRow() {
let tabel = document.getElementById("tabel");
let rows = tabel.getElementsByTagName("tr");
let indexNumber = document.getElementById("indexnumber").value;
Object.entries(rows).forEach(([key]) => {
if(key === indexNumber) {
tabel.deleteRow(indexNumber);
}
})
}
This works and deletes the row that the customer whats but it doesn't update the index numbers for the other rows. So when I delete row 5. My table will look like this.
https://imgur.com/Zz3sBSI
I figure I have to loop through all of the rows and set the index to the correct number again. Can anyone help me out :) ?
For the full code check:
https://codepen.io/Botert/pen/bJLLWL
grtz,
Botert
To answer your question, try adding the following snippet in your removeRow() function:
for (var i=1; i<rows.length; i++) {
var dataRow = rows[i].children[3];
dataRow.textContent = i;
}
Fiddle here: https://jsfiddle.net/ufszamv4/
It's outside of the scope of the question, but consider taking a different approach to the problem. Try placing your rows in an object that has its properties removed. The goal is to simply delete a row without having to update the rest of the data.
What I'm looking for is an individual column searching function (exactly as this datatables spreadsheet example) for the Handsontable spreadsheet plugin.
What's already existing and has been developed by the Handsontable team is :
Multiple filtering Excel-like (but included in the PRO version) - Cons for my case are that it's not free, and it doesn't quite fit well what I'm looking for.
Highlighting the cell(s) or row(s) based on an user input - The Con is that I need to only display the relevant row(s)
Is there such thing as displaying only the relevant row(s) based on multiple inputs from an user with Handsontable ?
Based on the solution of this blog, I managed to code a solution.
See this JS fiddle that answers all my requirements.
The main function I was looking for is this one :
// The function push every row satisfying all the input values into an array that is loaded
function filter() {
var row, r_len, col, c_len;
var data = myData; // Keeping the integrity of the original data
var array = [];
var match = true;
for (row = 0, r_len = data.length; row < r_len; row++) {
for(col = 0, c_len = searchFields.length; col < c_len; col++) {
if(('' + data[row][col]).toLowerCase().indexOf(searchFields[col]) > -1);
else match=false;
}
if(match) array.push(data[row]);
match = true;
}
hot.loadData(array);
}
What I did is keeping synchronized a table of Strings with the input fields (searchFields), compare the data of each row between inputs and their corresponding column, and push into an array the relevant row(s) to finally display the resulting array. This function is called for any change in the input fields which result in a live table filtering.
Note that I tried my solution for ~10k rows and their isn't any performance issue with Chrome, Firefox and IE.
Also note that I managed to find a solution to keep synchronized the current displayed table with the original data when editing the values, but this is IMO out of the scope of this question. Please let me know in the comment if you're interested about this.
I want to check whether the newly added row appear in first page or not. One way of doing it is get the index, but I wonder why it doesn't work, the index for me is not accurate at all.
function add_row(name, time_taken, attempts) {
var t = $('#dashboard').DataTable();
var node = '';
node = t.row.add([
'',
name,
time_taken,
attempts
]).draw().node();
$(node).attr('id', concatSpaces(name)).hide().fadeIn('slow');
var index = t.row('#' + concatSpaces(name)).index() // doesn't work
any thought? stuck for 2 hours long!
API method row().index() returns internal index which doesn't mean row position in the table based on current sorting column and method.
You need to use the code below instead to locate index of the row based on current sorting column and method:
var index = table.$('tr').index(node);
See this jsFiddle for code and demonstration.
I have the following code from selected rows in a grid......
var selected_rows = grid.getSelectionModel().getSelections();
Ext.each(selected_rows,function(item) {
var left_thumbnail_jpeg_name =item.data.left;
var right_thumbnail_jpeg_name = //select second cell along row
Can someone tell me how to set the second cell value along the row to a variable?
James
Please note that your tags did not include ExtJS and that is a bit misleading.
As for your question, since your grid in bound to a store of records you only need to change a record value for it to be imminently rendered to the grid.
in your case it will be :
item.set('right', YOUR NEW VALUE);
assuming that the next column is named right and that you have the new new value.