Responses Loop Continuously Changing

Could someone take a look at this section of my script and provide some feedback? The script is triggered whenever a response is submitted, and its purpose is to turn a column of data containing text strings into clickable hyperlinks to edit each response. However, the issue is that the hyperlinks are directing to the wrong responses, and with each new submission, the offset increases by 1. Here's an illustration:

ORIGINAL

  • Entry 1 - Hyperlink Leads to Entry 1
  • Entry 2 - Hyperlink Leads to Entry 2
  • Entry 3 - Hyperlink Leads to Entry 3
  • Entry 4 - Hyperlink Leads to Entry 4

AFTER 1 SUBMIT

  • Entry 1 - Hyperlink Leads to Entry 2
  • Entry 2 - Hyperlink Leads to Entry 3
  • Entry 3 - Hyperlink Leads to Entry 4
  • Entry 4 - Hyperlink Leads to Entry 1

AFTER 2 SUBMITS

  • Entry 1 - Hyperlink Leads to Entry 3
  • Entry 2 - Hyperlink Leads to Entry 4
  • Entry 3 - Hyperlink Leads to Entry 1
  • Entry 4 - Hyperlink Leads to Entry 2

Below is the code snippet used to create these hyperlinks:

var _sht = SpreadsheetApp.openById("XXX").getSheetByName("Sheet");
var formID = "YYY";
var form = FormApp.openById(formID);
var formResponses = form.getResponses();

for (var ii=0; ii<formResponses.length; ii++) {
  var tradeName = _sht.getRange(ii+2, 2).getValue();
  _sht.getRange(ii+2, 2).setFormula('=HYPERLINK("' + formResponses[ii].getEditResponseUrl() + '","' + tradeName + '")');
}  

Answer №1

To resolve the issue, I have implemented a customized solution based on AD:AM's answer found here. My modifications involve integrating an extra array to store the response to the 2nd question of each entry, which is then used as the title for the hyperlink. This approach helps maintain a tidy sheet by replacing lengthy hyperlinks with a more concise version linked to the existing data.

var tradeCol = 2, timeCol = 4;  
var data = _sht.getDataRange().getValues();
var timestamps = [], urls = [], trades = [], resultUrls = [];

for (var i=0; i<formResponses.length; i++) {
  timestamps.push(formResponses[i].getTimestamp().setMilliseconds(0));
  urls.push(formResponses[i].getEditResponseUrl());
  trades.push(formResponses[i].getItemResponses()[1].getResponse());
}

for (var j=1; j<data.length; j++) {
  resultUrls.push([
    data[j][timeCol-1]?
    '=HYPERLINK("' + urls[timestamps.indexOf(data[j][timeCol-1].setMilliseconds(0))] + '","' + trades[timestamps.indexOf(data[j][timeCol-1].setMilliseconds(0))] + '")':
    '']);
}

_sht.getRange(2, tradeCol, resultUrls.length).setFormulas(resultUrls);

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

Setting up a Node.js application with Nginx on DigitalOcean

While running my application on a DigitalOcean droplet using nginx, I encountered a peculiar issue. The app runs perfectly fine with http, but when switching to https, nginx throws a 502 BAD GATEWAY error. Despite trying various DigitalOcean guides and sco ...

Javascript alert: An issue has been detected when attempting to open a URL along with the user's input through Javascript

Having trouble with my javascript codes... I'm trying to create an input box and submit button. Whatever the user inputs in the box should be added to the default web URL, but it's not functioning as expected. The issue I'm facing is that ...

Understanding the performance of video in threejs when using getImageData

Edit; Check out the working codepen (you'll need to provide a video file to avoid cross-origin policy) https://codepen.io/bw1984/pen/pezOXm I'm currently trying to adapt the amazing rutt etra example from to utilize video (using threejs), but ...

Automatically redirect users on page refresh using jQuery

I am attempting to use jQuery to detect when the user refreshes the page in order to redirect, but I can't seem to get it working. Can someone help me figure out what is wrong with this code? <?php include 'instagram.php'; ?> <! ...

Error: The variable "deleted1" is not declared and cannot be used on the HTML button element's onclick

Hello, I need assistance from someone. I encountered an error message after trying to delete a row even though I have declared the button already. Error: deleted1 is not defined at HTMLButtonElement.onclick Could it be due to the script type being modul ...

Encountering an "undefined" error while implementing a registration system in Node.js and attempting to retrieve

Having recently delved into the world of javascript and nodejs, I am currently working on developing a registration system. The issue I'm facing is related to an error message indicating that "isEmail" is undefined. I have included my form validator a ...

The transition between backgrounds is malfunctioning

I want to create a smooth transition effect for changing the background of an element within a setInterval function. Currently, the background changes immediately, but I would like it to transition over a period of time. var act = true; setInterval(func ...

Creating Beautiful Math Equations with LaTeX in EaselJS

Can MathJAX or a similar tool be integrated into an EaselJS DisplayObject? I am looking for alternative options. I want to render text like $$ 5 + 3 - 3 = 5 $$ on a canvas that serves as an EaselJS stage. Ideally, I hope to achieve this using the Text Cl ...

Generate interactive tables using data from an XML file

Hello, I'm in the process of generating tables from an XML file using Node.js with the Express framework. I am utilizing npm modules xmldom and xmldoc for this task. The objective is to present these data tables on an ejs page. Here is the structure ...

Ways to incorporate sass:math into your vue.config.js file

While using vue-cli with Vue 2.6 and sass 1.49, I encountered errors in the console related to simple division calculations: Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0. I attempted to ...

PlaneGeometry at x=0 y=0 z=0 for three.js on a flat surface

Hi there! I have a code snippet that currently renders an image vertically, and I'm looking to modify it so that the PlaneGeometry is drawn horizontally instead. Rather than rotating it with mesh.rotation.x=THREE.Math.degToRad(-90);, I'd like it ...

Steps for adjusting button size in Sencha Touch

How can I resize a button in Sencha Touch 2 to make it smaller? I need to change its height. Any sample code you could provide would be greatly appreciated! Thanks navigationBar: { items:[{ xtype: 'button', ...

jQuery validation does not work properly when using .element(element) in a custom method

I am struggling with a custom rule that is supposed to check dependencies by validating other inputs it relies on. However, when I implement this validation, it seems like all other validations are being ignored. Here is my custom validation rule: jQuery ...

The alert box in Javascript appears before the execution of the statement preceding it

I am encountering a peculiar issue, which is not unexpected considering my limited experience with JavaScript. I am currently working on developing a basic high-low card game where two cards are drawn and the highest card wins. Below you can find the code ...

Choosing the Following Date from the Datepicker using Selenium IDE

I need the selenium IDE test case to automatically select a date following the steps outlined below: Start by clicking on the departure date to open the datepicker Loop through the dates starting with the currently selected day until the next available d ...

I'm looking for a simple calendar widget that can be clicked on using only plain JavaScript/jQuery and is compatible with Bootstrap

I'm in search of a simple clickable calendar widget to integrate into my website. I am using a combination of HTML, CSS, Bootstrap 5, and jQuery 3.6 for development. The functionality I require is for the calendar days to be clickable so that I can di ...

How can I dynamically adjust the stroke length of an SVG circle using code?

In my design project, I utilized Inkscape to create a circle. With the fill turned off, only the stroke was visible. The starting point was set at 45 degrees and the ending point at 315 degrees. After rotating it 90 degrees, here is the final outcome. < ...

Integrating dual Google Maps onto a single HTML page

I'm facing an issue with implementing two Google maps on a single page where the second map seems to be malfunctioning. Below is the code I am currently using: <style> #map-london { width: 500px; height: 400px; } #map-belgium { wi ...

Breaking Down the Process of Exporting a Next.js Static Website into Manageable Parts

I am facing memory issues while building my website using Next.js's Static HTML Export. The site has a large number of static pages, approximately 10 million. Is it feasible to export these pages in batches, like exporting 100k pages in each build ite ...

Tips for clearing out outdated information from a bar chart

My bar chart is receiving JSON data based on the selected dropdown value. The chart updates when the dropdown changes, but there seems to be a problem with the hover functionality causing the last visited value to shake the chart. Any suggestions on how ...