Iterating over a Google Apps Script and assigning various dispersed values

Without examples and context, titling this was quite challenging. Here goes...

I've created a Google Apps Script that searches through a column of student IDs (specifically in column A on the compiledDATA sheet) and assigns an award value to column B of the same row. While this works for a single student ID, I now require the script to iterate through and assign the same award value to all students within the GroupAwardIDs range located on a separate sheet called Group Awards.

For reference, here's a link to my sample spreadsheet: sample spreadsheet.

The values needing assignment are nonconsecutive, with potentially over a thousand to be processed at once.

How can I efficiently achieve this without hitting quota limits?

Below is the script (apologies for the numerous comments - they help me stay organized):

function AwardGroup() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var StarLog = sheet.getSheetByName("compiledDATA");
var GroupAward = sheet.getRangeByName("GroupAward").getValue();
var GroupAwardIDs = sheet.getRangeByName("GroupAwardIDs").getValue(); // THESE ARE THE IDS OF STUDENTS WHO WILL RECEIVE THE AWARD. HOW DO SET VALUES FOR ALL AND ONLY THESE IDS?
var IDs = sheet.getRangeByName("StudentIDs").getValues(); // all of the student IDs

for (var i = 0; i < IDs.length; i++) {
if (IDs[i] == "123461") { // THIS WORKS IF HARDCODE A SINGLE ID  
    var rowNumber = i+3; // find row and add 3 to compensate for GroupAward range staring at row 3
    var StarLogCurrent = StarLog.getRange("B"+rowNumber).getValue(); // locates students award log cell using A1 notation
    var appendAward = GroupAward.concat(StarLogCurrent); // prepends new award to previous awards

    StarLog.getRange("B"+rowNumber).setValue(appendAward); //write new star log

    }
  }
}  

Answer №1

When the StudentIDs ("compiledDATA!A3:A1000") and GroupAwardIDs ("'Group Awards'!B7:B1002") are the same, you can place GroupAward ("'Group Awards'!B3") in column "B" of "compiledDATA". If this is the correct understanding, consider the following modification for a possible solution among others.

Modification Suggestions:

  • Retrieve all GroupAwardIDs
  • Eliminate any empty elements within GroupAwardIDs
  • Identify IDs that match GroupAwardIDs and insert GroupAward accordingly
  • Insert values along with GroupAward

Revised Script:

Please make adjustments as shown below:

From:
// Previous script
To:
// Updated script

If there is any confusion or need for further modifications, feel free to reach out for assistance.

Edit :

To append GroupAward to the existing values in column B, please refer to the modified code snippet provided below. The delimiter used in this sample is ", ".

// Modified script

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

After being awaited recursively, the resolved promise does not perform any actions

When working with the Twitter API, I need to make recursive method calls to retrieve tweets since each request only returns a maximum of 100 tweets. The process is straightforward: Call the function and await it Make an HTTP request and await that If the ...

What is the best way to combine two arrays based on their ID values in Kotlin?

I am working with two arrays: val array1 = arrayOf( arrayOf("001", "Product name", "Product group"), arrayOf("002", "Product name", "Product group"), arrayOf("003", "Product n ...

"Linking and accessing data from different collections in MongoDB to enhance overall

Extracting information from an external API provides me with two separate data sets: one for football matches and another for football competitions. I store this information in MongoDB. Inquiring about a specific football match, I am interested in knowing ...

Node.js - Passport authentication consistently results in redirection to failure route

I am currently working on creating a login form using passportJs, but I keep encountering the issue of failureRedirect. Despite searching on stack overflow for a solution, I have not found the correct answer yet. Below is my code: Here is how I am crea ...

Send data using Javascript without having to refresh the page

As I work on submitting a form in JavaScript, the AJAX feature is functioning perfectly when manually submitting the form. However, there seems to be an issue when JavaScript attempts to submit it, resulting in a refresh. The current code snippet I am wor ...

Exploring the power of structures and pointer arrays in C++

Currently, I am facing a challenge in C++ while attempting to create a pointer array to structs. My primary objective is to have the flexibility to dynamically add pointers to the array. However, I seem to be struggling with the syntax. struct items ...

Can you please explain the query used in my code?

Can someone please explain the meaning of the variable named query in my code? I am using mongodb to fetch a collection called froggers. exports.get = function get(username, callback) { mongodb.open(function(err, db) { if (err) { return call ...

excessive memory usage in a simple react-native application

My experience with creating my first react native app has been more challenging than I initially expected. I'm having trouble understanding what I might be doing wrong. Initially, the app is simple, fetching data through Redux. componentWillMount() ...

What are the steps to switch to a root page after a successful sign-in with Ember-Auth?

After successfully implementing Ember-Auth using a pure token based approach, I am facing a challenge in redirecting users to the root of my app once they sign in. Although I know about actionRedirectable (refer to for details), since I am using a pure t ...

I have encountered a problem with ejs-mate where I am experiencing an issue with the <%- layout("path") %> command. Even though the path is accurate, it is not functioning correctly

Error Message: Unable to locate file at 'D:\Web Projects\major\views\listings\layouts\boilerplate.ejs' I have made numerous attempts to resolve this issue, but unfortunately, I keep encountering the same error. I ha ...

Browserify - combine external modules into a single bundle

I am a complete beginner in the world of browserify. I recently discovered this interesting module called peer-file, which allows for file transfer between two browsers. After reading the Usage section in its readme, I realized I needed to include the scri ...

What is the purpose of the Condition being executed in the screep tutorial?

Lately, I've been heavily focused on Python programming but recently delved into the realm of Screeps and Javascript. As part of a tutorial, there is this code snippet that moves a creep towards an energy source to harvest it: if(creep.store.getFreeC ...

Sending an AJAX associative array to a PHP associative array

I'm currently attempting to transmit form values to PHP utilizing the $.ajax method. Here is the HTML form structure I am working with: <form> <p> <label for="login">User ID:</label> <input type="text" name="login" id ...

What are the potential causes of receiving the error message "No Data Received ERR_EMPTY_RESPONSE"?

I often encounter this issue on my website, especially when I have a thread open. It seems to happen whenever I am actively checking for new posts and notifications via Ajax every 10 seconds or so. However, I'm not sure if this continuous reloading is ...

After executing my code, I encounter an unhandled error

I'm experiencing an issue in my project where every time I run node, the browser console displays the following error message: Uncaught TypeError: Failed to resolve module specifier "express". Relative references must start with either "/", "./", or " ...

Sending a Javascript string to PHP

I am trying to send a JavaScript string to PHP immediately after the code within the script tag. <script type="text/javascript"> var myvar = "mytext" ; <?php echo myvar ; ?> </script> Unfortunately, this approach is not functioning ...

the value in the array has not been increased

I am currently working on a code and facing an issue that I hope someone can help me with. Any assistance would be highly appreciated. I have created an array using the following syntax: intermediateBinCounts = (int *)malloc(bin_count * thread_count * ...

The Evolution of .back and .pushState: A Historical Comparison

Not exactly a question, but rather an interesting discovery resulting from a unique problem. It's more of a "Learn from my fail" moment. I've been working on writing unit tests for an HTML5 history hack for IE (using window.hash as a workaround ...

Ensuring Tablesorter maintains its sorting order when new data is added to the table

While using table-sorter for my table, I noticed that adding an entry to the table sometimes messes up the sorting order. How can I make sure that table-sorter maintains its current sorting state (ascending or descending) when an entry is added? I would li ...

Retrieving time zone using offset with javascript

I am looking for a way to schedule time-based events on my server operating in UTC time. For the user interface, I need to input 2 parameters: The local time when the scheduled event should trigger The timezone offset Instead of displaying timezone n ...