I need to append a single row of data that has 'Quantity Sold' cell populated - append

Data Input Page
Appended Data
Data from rows 5 and 6 have been appended into sheet, but I just want from the row where data is shown (B7)
function appendSoldData() {
const ss =SpreadsheetApp.getActiveSpreadsheet();
// Collect the data.
const sourceRange = ss.getRangeByName("PlantData");
const inputRange = ss.getRangeByName("QtySold")
const sourceVals = sourceRange.getValues().flat();
// Check for row that has quantity sold - this is what i want to append to 'Form responses 1'
const anyPopulatedCell = sourceVals.findIndex(cell => cell =="");
if(anyPopulatedCell !== 1){
}
// Gather current date time
const date = new Date();
const data = [date,...sourceVals];
//Append the data.
const destinationSheet = ss.getSheetByName("Form responses 1");
destinationSheet.appendRow(data);
// Clear the source sheet rows.
inputRange.clearContent();
ss.toast("Sale Added to 'Form responses 1'!");
};

Related

is there a way to delete data from a firebase real time database (using flutter) after 1 day?

I want to add data that stays in the database for 1 day by default and then get deleted. Unless I set a different time (more than one day).
You can create something like below method and you need to upload that on Firebase Cloud Function
const CUT_OFF_TIME = 24 * 60 * 60 * 1000; // 2 Hours in milliseconds.
exports.deleteOldMessages = functions.database.ref('[path]').onWrite(async (change) => {
const ref = change.after.ref.parent; // reference to the parent
const now = Date.now();
const cutoff = (now - CUT_OFF_TIME) / 1000; // convert to seconds
const oldItemsQuery = ref.orderByChild('seconds').endAt(cutoff);
const snapshot = await oldItemsQuery.once('value');
// create a map with all children that need to be removed
const updates = {};
snapshot.forEach(child => {
updates[child.key] = null;
});
// execute all updates in one go and return the result to end the function
return ref.update(updates);
});
You can checkout below link for reference as well.
souce

I want to use the content of a cell in a google sheet to control whether to send an e-mail out or not

I have a spreadsheet for recording customer samples. A column [I] is used to calculate when the original entry date is over a certain period which then displays an overdue message using an if statement. I want to trigger a script to check this column daily and if 'overdue' is found to send an email to an address contained in another column [C]. I am also using another column [J] to return a message when an email has been sent. I am using the script below but am returning errors
The script marks all rows in column J with the sent email message
I appear to be collecting a bigger array of data have needed [adding two rows the the bottom]
Anyone any ideas?
//Setup the function
function autoMail () {
var ss = SpreadsheetApp.getActiveSpreadsheet(); //Get the active spreadsheet
var sheet = ss.getSheetByName( 'TS_Requests' ); //Get the active spread
var startRow = 3; // Start of row that going to be process considering row 2 is header
var lastRow = sheet.getLastRow(); // Get the last row of data to be process
var lastColumn = sheet.getLastColumn(); // Get the last column of data to be process
var range = sheet.getRange(startRow,1,lastRow,lastColumn); //Getting the specific cell to be process
var data = range.getValues(); // Get the values inside the cell
for(var i=0;i<data.length;++i){
var row = data[i];
var email = row[2]; // Grab the email column. C in this case
var customer = row[3]; // Grab data for Email body
var item = row[5]; // Grab data for Email body
var description = row[6]; // Grab data for Email body
var status = row[8]; // Grab the column containing the value needed to be checked.
var EmailSent = row[9]
if (EmailSent != 'Email_Sent') { //Prevents e-mail being sent in duplicate
if(valstatus ='Overdue'){ // Check the values, if it's what's needed, do something
MailApp.sendEmail(email, 'Your sample request is overdue', customer + ' - ' + item + ' - ' + description); // if condition is met, send email
sheet.getRange(startRow + i, 10).setValue('Email_Sent');
}
}
}
}

ag-grid + valuegetter + row grouping

ag-grid valuegetter + row grouping, on cell click need to get params data.
In case of header & other cells except grouped row we are getting params data.
column definition of ag-grid looking like below:
const scopeOutCurrIndex = function (col, rSeg, isPVInColSegment) {
return function (params) {
return params.data;
 }
};
const colDefObj: any = {};
// for E-NG-GRID
colDefObj['rowGroup'] = true;
colDefObj['hide'] = true;
colDefObj.headerName = this.segLabelMap
? this.gridUtilService.getSegmentLabel(rSegments[i], this.segLabelMap)
: rSegments[i];
colDefObj["isRowSegment"] = true;
colDefObj["headerId"] = rSegments[i];
//Set width for column
colDefObj["width"] = this.calColumnWidth(colDefObj.headerName);
colDefObj["moduleId"] = moduleIds ? moduleIds[0] : moduleIds;
colDefObj.valueGetter = scopeOutCurrIndex(rSegments[i], rSegments, this.isPVInColSegment);
const scopeOutCurrIndex = function (col, rSeg, isPVInColSegment) {
return function (params) {
return params.node.allLeafChildren[0].data;}
};
We can get data from leaf children, ag-grid provide flexible to get data from leaf children.

Corrupt records from OpenXML Spreadsheet creation

I'm trying to generate a simple XLSX file using OpenXML but I'm getting an error when I open my file and the only info in the repairedRecord part of the log file is this:
Repaired Records: Cell information from /xl/worksheets/sheet1.xml part
The strange thing is that all the cells I'm trying to write do have the value I expect them to have. I'm just trying to write a single header row right now, where the headers is just an IEnumerable<string>:
using (var doc = SpreadsheetDocument.Create(filename, SpreadsheetDocumentType.Workbook)) {
var workbookPart = doc.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
var worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet();
var sheets = workbookPart.Workbook.AppendChild(new Sheets());
var sheet = new Sheet {
Id = workbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Sheet 1"
};
sheets.Append(sheet);
workbookPart.Workbook.Save();
var sheetData = worksheetPart.Worksheet.AppendChild(new SheetData());
var row = new Row { RowIndex = 1 };
var column = 1;
foreach (var header in headers)
row.AppendChild(new Cell {
CellReference = GetColumnLetter(column++) + "1",
DataType = CellValues.SharedString,
CellValue = new CellValue(header)
});
sheetData.Append(row);
workbookPart.Workbook.Save();
}
If you're inserting a string value, you should be using CellValues.InlineString
foreach (var header in headers)
row.AppendChild(new Cell (new InlineString(new Text(header))) {
CellReference = GetColumnLetter(column++) + "1",
DataType = CellValues.InlineString
});

Automatic Email from Google Sheets with email from row

I am trying to apply this code to a google sheet which I use to track name change requests. The customer submits a form and when they don't submit all the required information I select rejected from the dropdown on the spreadsheet. I have the form collect the username when the customer submits the form. I was wondering if it is possible to modify the code below to grab the email address from the row of the active cell that the status was changed and email the customer to inform them their request is rejected.
function sendEmail(email_address, email_subject, email_message) {
var status = ScriptProperties.getProperty('Order Status') + "";
var value = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FCNC Responses").getActiveCell().getValue().toString();
if (value.match("Rejected" ) && status.match("")) {
ScriptProperties.setProperty('Order Status', '')
MailApp.sendEmail('username#nps.gov', 'Rejected Fleet Card Name Change', '. Fleer User, Please review the Fleet Card Name Change page for Status Updates.": ');
}
else {
if (!value.match("Rejected" ))
ScriptProperties.setProperty('Order Status', '')
}
}
You can use a function with dataRange.getValues().
getValues()
Returns the rectangular grid of values for this range. Returns a two-dimensional array of values, indexed by row, then by column. The values may be of type Number, Boolean, Date, or String, depending on the value of the cell. Empty cells will be represented by an empty string in the array. Remember that while a range index starts at 1, 1, the JavaScript array will be indexed from [0][0].
Here is a code sample from a related SO question:
function findCell() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var dataRange = sheet.getDataRange();
var values = dataRange.getValues();
for (var i = 0; i < values.length; i++) {
var row = "";
for (var j = 0; j < values[i].length; j++) {
if (values[i][j] == "User") {
row = values[i][j+1];
Logger.log(row);
Logger.log(i); // This is your row number
}
}
}
}
From there you can add the code that will send email if the value of the specific cell is rejected.
Happy coding, hope it helps!