Need help creating an array of objects in Javascript - javascript

I have two Sheets
A "MEMBER" Sheet - 600 rows.
A "MODERATOR" Sheet - 13 rows (this is a subset of the "MEMBER" sheet)
Both sheets share a "Member Key" column - all unique values to identify the members.
I want to create a function that does the following
"...For every row in the MEMBER sheet..."
"...Compare the Member Key column in the MODERATOR sheet."
"If the Member Key column matches..."
"...pull values from that specific row in the MEMBER sheet..."
"and copy them into the MODERATOR sheet row with the matching KEY column"
The code is supposed to update the Moderator record with information from its correspondence Member record
the code I wrote for it is below.
The code runs, but the values don't update. I assume it's related to the for loop I applied. I'm hoping to resolve this issue by using object functions in the arrays, but I've had diffiuclty applying them in my code.
Grateful for any feedback on my question or code in general
function Moderator_Update() {
var Metrics = SpreadsheetApp.openById("10Wl1B4AtdLHJXBbLbMQbSdtRyAb61biCWYpOQEEywIY"); // METRICS spreadsheet
var Data = SpreadsheetApp.getActiveSpreadsheet(); // DATA spreadsheet
var ModsDataSheet = Data.getSheetByName("The Moderator_Numbers"); // DATA "Member" sheet
var ModsAllValues = ModsDataSheet.getRange(2, 1, ModsDataSheet.getLastRow()-1,ModsDataSheet.getLastColumn()).getValues(); //All values in DATA "Members" sheet
var MembersDataSheet = Data.getSheetByName("The Member_Numbers") // DATA "Moderator" sheet
var MembersAllValues = MembersDataSheet.getRange(2, 1, MembersDataSheet.getLastRow()-1,MembersDataSheet.getLastColumn()).getValues();
for(var MO = ModsAllValues.length-1;MO>=0;MO--) // for each row in the "Moderator" sheet...
{
for(var M = MembersAllValues.length-1;M>=0;M--) // for each row in the "Member" sheet...
{
if (MembersAllValues[M][17] == ModsAllValues[MO][27]) // If Member KEY matches Moderator Key.
{
// delcare the following variables with values from the Member Sheet
var Mod_MemberName = MembersAllValues[M][0];
var Mod_MemberWebPage = MembersAllValues[M][2];
var Mod_MemberTag = MembersAllValues[M][4];
var Mod_MemberFirstName = MembersAllValues[M][5];
var Mod_MemberLastName = MembersAllValues[M][6];
var Mod_MemberEmail = MembersAllValues[M][7];
// assign those values to the following cells in the Moderator Sheet
ModsAllValues[MO][0] = Mod_MemberName;
ModsAllValues[MO][2] = Mod_MemberWebPage;
ModsAllValues[MO][5] = Mod_MemberTag;
ModsAllValues[MO][6] = Mod_MemberFirstName;
ModsAllValues[MO][7] = Mod_MemberLastName;
ModsAllValues[MO][8] = Mod_MemberEmail;
}
}
}
var ModDestinationRange = ModsDataSheet.getRange(2, 1, ModsAllValues.length, ModsAllValues[0].length);
ModDestinationRange.setValues(ModsAllValues);
}
Moderator Sheet
Member Sheet

Try this:
It's not fastest possible solution but this way you don't have to worry about the effects of overwriting values that are not a part of the update.
function Moderator_Update() {
var Data=SpreadsheetApp.getActiveSpreadsheet();
var mdsh=Data.getSheetByName("The Moderator_Numbers");
var mdvA=mdsh.getRange(2,1,mdsh.getLastRow()-1,mdsh.getLastColumn()).getValues();
var mrsh=Data.getSheetByName("The Member_Numbers");
var mrvA=mrsh.getRange(2,1,mrsh.getLastRow()-1,mrsh.getLastColumn()).getValues();
var mdkeyA=mdsh.getRange(2,28,mdsh.getLastRow()-1,mdsh.getLastColumn()).getValues().map(function(r){return r[0];});
for(var j=0;j<mrvA.length;j++) {
var i=mdkeyA.indexOf(mrvA[j][17]);
if(i>-1){
mdsh.getRange(i+2,1).setValue(mrvA[j][0]);
mdsh.getRange(i+2,3).setValue(mrvA[j][2]);
mdsh.getRange(i+2,6).setValue(mrvA[j][4]);
mdsh.getRange(i+2,7).setValue(mrvA[j][5]);
mdsh.getRange(i+2,8).setValue(mrvA[j][6]);
mdsh.getRange(i+2,9).setValue(mrvA[j][7]);
}
}
}

Related

How to combine the getRange() function with a forLoop when trying to piece together your data in Google Apps Script?

EDIT:
Since my problem is rather difficult to describe I added an example of my data which hopefully shows what I'd like to achieve:
https://docs.google.com/spreadsheets/d/1Wa_z2e2br53usul3uMy8nczXushvhPFRiIlZ5M2ueYU/edit?usp=sharing
I hope it's okay to do so.
I could need some help with the following problem: I'm trying to create a summary sheet for a variety of data sheets. Each data sheet, i.e., "Sheet1", "Sheet2", "Sheet3", e.g., has an ID variable that I use for splitting my data within each data sheet.
What I'm trying to do is to loop through all my data sheets, grab the data in each sheet, split the data for each sheet by ID, so that I have all rows with As, Bs and Cs for each sheet, and then put all these pieces together BUT SEPARATED BY A COUPLE OF EMPTY ROWS in my summary sheet.
What I have done thus far is this:
function main() {
// SETUP.
var app = SpreadsheetApp;
var workbook = app.getActiveSpreadsheet();
var activeSheet = workbook.getActiveSheet();
// CREATE NEW SUMMARY SHEET.
var targetSheet = workbook.getSheetByName("Summary");
if (!targetSheet) {
workbook.insertSheet("Summary",1);
}
// ARRAY OF SHEETS USED IN MY LOOP.
var tabs = ["Sheet 1",
"Sheet 2",
"Sheet 3"];
// LOOP FOR ALL SHEETS.
for (var i = 0; i < tabs.length; i++) {
var sheet = workbook.getSheetByName(tabs[i]);
// GRAB THE ORIGINAL DATA.
var originalData = sheet.getRange(5, 1, sheet.getLastRow()-5, sheet.getLastColumn()).getValues();
// SELECT ID AND SORT BY UNIQUE IDs.
var range = sheet.getRange(5,2,sheet.getLastRow()-5,1).getValues();
var range = [].concat.apply([], range);
let uniqueValues = range.filter((v, i, a) => a.indexOf(v) === i);
// GRAB THE UNIQUE DATA PIECES IN EACH SHEET.
for (var t = 0; t < uniqueValues.length; t++) {
var filterText = uniqueValues[t];
var newData = originalData.filter(function(item) {
return item[1] === filterText;
});
// DO SOMETHING I HAVE YET TO DEFINE
// e.g., exclude rows that fall beneath a certain threshold.
// WRITE DATA PIECES BACK TO SUMMARY SHEET.
workbook.getSheetByName("Summary").getRange(???).setValues(newData);
}
}
}
The code above works fine and does slice my data on different data sheets correctly. However, setting the pieces back together is an issue. Right now the data pieces of each iteration is overwritten by the next one.
What I need to do is to figure out a way how to grab these different slices of data based on my ID and then put them together in a way shown in my example data (linke above).
I think I'm lost somewhere between different loops and the data stored temporarily within the loops.
Answer:
After gathering the data you need to:
Run through the rows
Check the product name
Push rows with the same product name to separate arrays
Use setValues() to set the data of each product
Add 4 blank rows
Code Modifications:
Before your LOOP THROUGH ALL SHEETS for loop, add an array declaration:
var dataSets = [];
Then, replace the following line:
workbook.getSheetByName("Summary").getRange(???).setValues(newData);
With:
dataSets.push(newData);
And after the for loop, do the data processing set out in the first section of this answer:
// Create a 2D array to push the data to:
var allData = [[],[],[]];
// loop through the Data sets and push them to the correct element of allData:
dataSets.forEach(function(dataSet) {
dataSet.forEach(function(row) {
if (row[1] == "Product A") {
allData[0].push(row)
}
else if (row[1] == "Product B") {
allData[1].push(row)
}
else if (row[1] == "Product C") {
allData[2].push(row)
}
})
})
// Define the next row to add data to in the Summary sheet:
var nextRow = 1;
// Set the data to the Summary sheet:
allData.forEach(function(product) {
var noOfColumns = product[0].length;
var noOfRows = product.length;
workbook.getSheetByName("Summary").getRange(nextRow, 1, noOfRows, noOfColumns).setValues(product)
nextRow += noOfRows + 4;
});

How do I perform row call using Google App Script

I have done a bit of research on how I can perform a rowcall using google app script but have a little challenge and will appreciate any assitance on this.
So this code looks at the first column and gets the values to be used in renaming new tabs
function newSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getActiveSheet();
var sheet1 = ss.getSheetByName("main")
var getNames = sheet1.getRange("A2:A").getValues().filter(String).toString().split(",");
for (var i = 0; i < getNames.length; i++) {
var copy = ss.getSheetByName(getNames[i]);
if (copy) {
Logger.log("Sheet already exists");
} else {
templateSheet.copyTo(ss).setName(getNames[i]);
ss.setActiveSheet(ss.getSheetByName(getNames[i]));
ss.moveActiveSheet(ss.getNumSheets());
}
}
}
The sheet
What I would like to do and is becoming a challenge, is While creating a new tab with a name then, I would like to copy the entire row to the new tab/sheet. e.g for the sheet Levi only the raw with Levi Data be copied to the sheet.
At the moment my code copies the entire source sheet to the new tabs/sheets. I will really appreciate any help with this
Proposed solution:
Now you are using the main sheet as a template so when you use it with the function .copyTo you will copy the whole content.
You will have to get the whole row corresponding to the index of the given name.
Approach
You will need an extra filtering to get the correct row values you want to put in the new sheet.
I will filter the name column (column A) and get the index of the name in the loop.
(I am assuming you can have some gaps so the index of the for loop would not be enough).
Once i found the corresponding index i will need to increment it by one because row indexing starts from 1 in Google Spreadsheets.
Now i can easily get the row using the function .getRange(row, column, numRows, numColumns).
I am using the function .getLastColumn() to compute the numColumns parameter.
Now I can use the function .appendRow() to insert the row in the new sheet I just created with the .insertSheet() function.
Sample Code:
function newSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getActiveSheet();
var sheet1 = ss.getSheetByName("main")
var getNames = sheet1.getRange("A2:A").getValues().filter(String).toString().split(",");
for (var i = 0; i < getNames.length; i++) {
var copy = ss.getSheetByName(getNames[i]);
if (copy) {
Logger.log("Sheet already exists");
} else {
//The copyTo function will copy the entire sheet
//templateSheet.copyTo(ss).setName(getNames[i]);
var rowIndex = sheet1.getRange("A:A").getValues().flatMap(value => value[0]).indexOf(getNames[i]) + 1;
var rowValues = sheet1.getRange(rowIndex, 1, 1, sheet1.getLastColumn()).getValues();
ss.insertSheet(getNames[i]).appendRow(rowValues[0]);
ss.setActiveSheet(ss.getSheetByName(getNames[i]));
ss.moveActiveSheet(ss.getNumSheets());
}
}
}
Edit
In the case the names are repeated you will have to filter the column and extract the corresponding indexes.
First you will have to get a set for your getNames variable. (otherwise you will have repetitions).
var getNames = [...new Set(sheet1.getRange("A2:A").getValues().filter(String).toString().split(","))];
Then you will have to map the row indexes to the names in the column A.
Now you can filter by the getNames values and you will obtain the row indexes.
In the end you can append to the new sheet the rows at the corresponding indexes.
var rowIndexes = sheet1.getRange("A:A").getValues()
.map((value, index) => [value[0], (index + 1)])
.filter(value => value[0] === getNames[i]);
var namedSheet = ss.insertSheet(getNames[i]);
rowIndexes.map(index => {
var rowValues = sheet1.getRange(index[1], 1, 1, sheet1.getLastColumn()).getValues();
namedSheet.appendRow(rowValues[0]);
});
References:
Class Sheet

Compare multiple values in one array

I need some help determining how i can compare 4 columns of one row with 4 columns of another row.
To explain, I have two tables, which both have four columns: State, Area, City & Location.
PINPOINT table - this table has a unique combination of values
FEED table - this table has a recurring combination of values, as well as the KEY value from the PINPOINT Table.
What i want is a code that says
"If a row from column CL in the FEED sheet contains the Key Value from column K in the PINPOINT sheet,
...but columns CN to CQ that FEED sheet row doesn't have the same values as column A-D in the PINPOINT table...
update column CN to CQ the FEED sheet with the same combination of values as A-D in the PINPOINT table."
I pasted the latest code i have below, as well as the images. Admittedly, this code is a mess I just started learning code, so I'm happy to rewrite this if someone proposes a solution.
In any case, any insight into how i should write this will be quite helpful.
var Data = SpreadsheetApp.getActiveSpreadsheet(); // DATA spreadsheet
var PinpointDataSheet = Data.getSheetByName("The Pinpoints") // DATA "Pinpoint" sheet
var PinpointAllValues = PinpointDataSheet.getRange(2, 1, PinpointDataSheet.getLastRow()-1,PinpointDataSheet.getLastColumn()).getValues();
var FeedDataSheet = Data.getSheetByName("The Feed_Raw") // DATA "Feed" sheet
var FeedAllValues = FeedDataSheet.getRange(2, 1, FeedDataSheet.getLastRow()-1,FeedDataSheet.getLastColumn()).getValues();
var PinpointStateObj = {}; // Object for "Locale" values
var PinpointAreaObj = {}; // Object for "Locale" values
var PinpointCityObj = {}; // Object for "Locale" values
var PinpointSpotObj = {}; // Object for "Locale" values
for(var P = PinpointAllValues.length-1;P>=0;P--) // put Pinpoint values in array..
{
PinpointStateObj[PinpointAllValues[P][0]] = PinpointAllValues[P][10];
PinpointAreaObj[PinpointAllValues[P][1]] = PinpointAllValues[P][10];
PinpointCityObj[PinpointAllValues[P][2]] = PinpointAllValues[P][10];
PinpointSpotObj[PinpointAllValues[P][3]] = PinpointAllValues[P][10];
}
for(var F = FeedAllValues.length-1;F>=0;F--) // for each row in the "Feed" sheet...
{
var Feed_GeotagKey = FeedAllValues[F][90]; // Pinpoint Key values in Feed sheet
{
// If Pinpoint array dont match feed values
if ((PinpointStateObj[Feed_GeotagKey] != FeedAllValues[F][95]) || (PinpointAreaObj[Feed_GeotagKey] != FeedAllValues[F][96])
|| (PinpointCityObj[Feed_GeotagKey] != FeedAllValues[F][97]) || (PinpointSpotObj[Feed_GeotagKey] != FeedAllValues[F][97]))
{
FeedAllValues[F][95] = PinpointAllValues[P][0]; // ...Change FYI Category Name in FYI Topic Sheet
FeedAllValues[F][96] = PinpointAllValues[P][1];
FeedAllValues[F][97] = PinpointAllValues[P][2];
FeedAllValues[F][98] = PinpointAllValues[P][3];
}
}
}
Geotag Sheet - unique values "Dark column"
Feed Sheet - recurring values - "Highlighted column"

Writing Sorted Table Data to the Table in a Separate Format using Google Sheets

I'm relatively new to javascript and definitely new to google scripting.
I have a tab where raw data entry happens. I have another tab where that data is sorted, and an approval date is written next to that line later. I want that date to reflect back to the first tab in the proper line, and I also want to make sure that it stays on the proper line in the second tab (even after new lines are added and sorted in).
Attached is an example sheet with only a few lines. In reality I have more columns but they are irrelevant here.
https://docs.google.com/spreadsheets/d/14dh0IW7vO8c2OLc2O8WE-Ptuh3MJfLWTESVMA_DpOv0/edit?usp=sharing
My second tab uses the sheets SORT function. When A date is typed though, it creates an error. I was going to account for this by using onEdit() function and writing the date into the correct line in the first tab, then clearing the date column in the second tab (to avoid the error and keep it aligned).
''javascript
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet2 = ss.getSheetByName("check released");
var sheet1 = ss.getSheetByName("Log");
var job2 = sheet2.getRange("A2:A1000").getValues();
var job1 = sheet1.getRange("A2:A1000").getValues();
var draw2 = sheet2.getRange("B2:B1000").getValues();
var draw1 = sheet1.getRange("B2:B1000").getValues();
var inv2 = sheet2.getRange("C2:C1000").getValues();
var inv1 = sheet1.getRange("C2:C1000").getValues();
var dates2 = sheet2.getRange("D2:D1000");
var dates_values = sheet2.getRange("D2:D1000").getValues();
var dates1 = sheet1.getRange("D2:D1000");
var indices = []
var to_paste = []
for(var i = 0; i < job2.length; i++) {
var job2_Value = job2[i][0];
var draw2_Value = draw2[i][0];
var inv2_Value = inv2[i][0];
for(var j=0; j<job2.length; j++) {
var job1_Value = job1[j][0];
var draw1_Value = draw1[j][0];
var inv1_Value = inv1[j][0];
if((job2_Value != "") && (job1_Value == job2_Value) && (draw1_Value === draw2_Value) && (inv1_Value === inv2_Value)) {
indices.push([i]);
}
}
}
for(k in indices) {
to_paste.push([dates2[k]])
}
Logger.log(to_paste)
dates1.setValues(to_paste)
dates2.clearContent()
Logger.log("Cleared on check released page")
};
'''
This is the code that I've written, but it doesn't work and I don't know why. I also don't know where to find the console log.
You have a sheet "check released" that takes values from "sheet "Log". Your aim is enter a "release date" on "check released" and have that updated to "Log", and then reflected in "check released". The approach you took was to edit the actual linked "release date" value on "check released". Not surprisingly this wasn't successful because it was merely taking date from "Log".
In the following code:
I have used a helper column on "check released" where the date can be entered.
The onEdit(e) script detects the new value, finds the equivalent row on "Log".
The script updates the "Date" column on "Log" - at this point, the values on "check released" are automatically updated.
Then the script deletes the value in the helper column.
Matching from "Log" to "check released"
The matching of rows from "check released" to "Log" relies on several elements:
No record has a truly unique identifier.
However, the values of Job, Draw and Invoice numbers, when each is converted to a string and concatenated, generate a unique value that can be used to compare values from "Log" to "check released".
The values on "Log" are processed in a loop to create a 1D array of concatenated values.
Event objects provide the edited Row on "check released"; and the Job, Draw and Invoice values in that row are concatenated.
Using the Javascript indexOf method, the script 'finds' the row on "Log" that matches the unique concatenated value from the edited row.
Other items to note:
the actual size of the data range on "Log" and "check released" is determined by using getlastRow()
getRange and getValues are run once each for "Log" and "check released"
Meaningful names for variables have been chosen to reflect their purpose; this assists in reading and understanding the code.
function onEdit(e) {
// 5824330602
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ui = SpreadsheetApp.getUi();
var logsheet = "Log";
var log = ss.getSheetByName(logsheet);
var checkrsheet = "check released";
var checkr = ss.getSheetByName(checkrsheet);
// get Log data
var logFR = 2;
var logLR = log.getLastRow();
var logLC = 4;
var logRange = log.getRange(logFR,1,logLR-logFR+1,logLC);
// Logger.log(logRange.getA1Notation());// DEBUG
var logValues = logRange.getValues();
// get check released data
var checkrRange = checkr.getRange(logFR,1,logLR-logFR+1,logLC);
//Logger.log(checkrRange.getA1Notation());
var checkrValues = checkrRange.getValues();
// build array of uniquelogitems
var logitems=[];
for (var i=0; i<logValues.length; i++) {
var logjob = logValues[i][0].toString();
var logdraw = logValues[i][1].toString();
var loginv = logValues[i][2].toString();
var logid = logjob+logdraw+loginv;
//Logger.log("DEBUG: LOG: Job= "+logjob);
//Logger.log("DEBUG: LOG: draw= "+logdraw);
//Logger.log("DEBUG: LOG: inv= "+loginv);
//Logger.log("DEBUG: LOG: concat= "+logid);
var logid = logjob+logdraw+loginv;
logitems.push(logid);
}
//Logger.log(logitems); //DEBUG
// get the event objects
var editedRow = e.range.getRow();
var editedCol = e.range.getColumn();
var editedSheet = e.range.getSheet().getSheetName();
var editedValue = e.value;
// Logger.log("DEBUG: row = "+editedRow+", column = "+editedCol+", Sheet = "+editedSheet)
// apply logic to test whether this edit should be processed
// Column 5 ("E") is the helper column
if(editedRow >= logFR && editedRow <=logLR && editedCol === 5 && editedSheet === checkrsheet){
// the edit is in Column E (Date), between the first and last rows of data, on the "check released" sheet
//Logger.log("DEBUG: edit is OK. edit row = "+editedRow+". Keep processing");
var checkrjob = checkrValues[editedRow-2][0].toString();
var checkrdraw = checkrValues[editedRow-2][1].toString();
var checkrinv = checkrValues[editedRow-2][2].toString();
var checkritem = checkrjob+checkrdraw+checkrinv;
//Logger.log("DEBUG: Checkr: job="+checkrjob+", draw= "+checkrdraw+", inv = "+checkrinv+", Item = "+checkritem);
var match = logitems.indexOf(checkritem);
//Logger.log("DEBUG: Matching row = "+match);
// get the existing date
var existingdate = logValues[+match+1][3];
var cell = log.getRange(+match+2,4);
//Logger.log("DEBUG: the update cell = "+cell.getA1Notation())
// date field is a date, so update new date
cell.setValue(editedValue);
cell.setNumberFormat('mm/dd/yy');
e.range.clearContent();
//Logger.log("DEBUG: updated date on Log")
}
else{
// the edit didn't meet the rule
//Logger.log("DEBUG: edit did NOT meet criteria. Do not proceed")
}
};
Column E - Helper Column

Updating a sheet with a value if strings match on two sheets

Sheet 2 has all the items and their statuses, while Sheet 1 has only some of the items from Sheet 2. I want to be able to see every time an item mentioned on Sheet 1 is listed as having a status update, i.e. e date, on Sheet 2.
Here's what I have so far, but having trouble calling the right range to work with. Is there a simpler way to do what I want to do?
function statusupdate() {
var activesht = SpreadsheetApp.getActiveSpreadsheet();
var statussht = activesht.getSheetByName("Sheet 2"); //get sheet on which status update occurs
var statusrng1 = statussht.getRangeByName('B');
var statusrng2 = statussht.getRangeByName('C');
var mainsht = activesht.getSheetByName("Sheet 1"); //get sheet where you show a specific thing has been updated, if that thing mentioned here.
var mainrng = mainsht.getRangeByName('F');
if (statusrng1 == mainrng) {
var date = statusrng2.getValue();
var daterng = mainrng.getRangeByName('E');
daterng.setValues(date);
}
}
Spreadsheet formula
You can have the rows in one sheet follow those in another without using a script. For example, say we have a sheet named Items that contains one row for every item we carry, with the item number in the first column.
We can use VLOOKUP() to search for the row containing info about individual items, and select specific columns from it.
For example, this formula would be used in B2, and could be copied to other cells in our sheet:
=VLOOKUP($A2,Items!$A$2:$C$7,COLUMN(),false)
Script
There are a few issues with your script.
.getRangeByName('B') - This method gets a named range. Given the name, I suspect you mean to get column B, and NOT a named range. If that's the case, you could use this instead:
var statusrng1 = statussht.getRange('B:B');
In A1Notation, the range B:B is the entire column B.
You intend to copy values, so there is another step required beyond identifying ranges; you need to first read the values from a range, and then later write them to a different range. For that, you need to use methods like getValues() and setValues().
Here's an updated version of your script, adapted to the example spreadsheet described above.
function statusupdate() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//get sheet on which status update occurs
var statusSheet = ss.getSheetByName("Items");
var statusRange = statusSheet.getDataRange();
var statusData = statusRange.getValues();
//get sheet where you show a specific thing has been updated, if that thing mentioned here.
var trackingSheet = ss.getSheetByName("Tracking");
var trackingRange = trackingSheet.getDataRange();
var trackingData = trackingRange.getValues();
// Loop over all rows in the Tracking sheet to update from the Items sheet
// Start with row=1, because row 0 contains headers
for (var row=1; row<trackingData.length; row++) {
var item = trackingData[row][0];
if (item == '') continue; // skip rows without item #
// Look for item in Items sheet
var statusRow = null;
for (var sRow=1; sRow<statusData.length; sRow++) {
if (statusData[sRow][0] == item) {
// Found our match, grab that row
statusRow = statusData[sRow];
break;
}
}
// If we found a matching row, copy the status
if (statusRow) {
// Customize this depending on how your sheets are organized
trackingData[row][1] = statusRow[1];
trackingData[row][2] = statusRow[2];
}
}
// All values have been copied to trackingData, now write to sheet
trackingRange.setValues(trackingData);
}

Categories