Transfer information between two spreadsheets whenever changes are made

I've exhausted all my options but I just can't seem to get this working =/

My goal is to transfer data from one spreadsheet to another using setValues() because the link feature isn't sufficient for me. I also need to maintain the trigger on edit.

So, I devised a function called AddConvocacao that runs every time there's a change in the sheet.

function addConvocacao(e){
  var linha = e.range.getRow(); //get the line number where the edit occurs
  var nome = e.source.getActiveSheet().getRange(linha,2).getValue(); //retrieve the field value

  var targetSheet = SpreadsheetApp.openById('1iQbZ7iB9ddc-HwLK9vG0eVEeWWqXKJZ0ry7U_Hm4SkQ') //access the other spreadsheet 
  var targetName = targetSheet.getSheetByName('Pac'); //select the specific tab
  var lastRow = targetName.getLastRow(); //determine the last row in the tab
  lastRow = lastRow+1; //increment by 1
  
 targetName.getRange(lastRow, 2).setValue(nome); //set the value 
 // targetName.getRange(lastRow, 3).setValue(valorCol7);
 // targetName.getRange(lastRow, 5).setValue(dose);
 // targetName.getRange(lastRow, 6).setValue(diagnostico);
 // targetName.getRange(lastRow, 7).setValue(medico);
}

Why doesn't it work when I use on edit?

Thank you so much! =)

Answer №1

My approach was slightly different. Instead of directly manipulating column values, I opted to use checkboxes in column one to capture values from column 2 and transfer them to another spreadsheet at the bottom of column 2.

function onMyEdit(e) {
  //e.source.toast('entry');
  const sh = e.range.getSheet();
  //Logger.log(JSON.stringify(e));
  if (sh.getName() == 'Sheet1' && e.range.columnStart==1 && e.value=="TRUE") {
    //e.source.toast('cond');
    const v = sh.getRange(e.range.rowStart, 2).getValue();
    var tss = SpreadsheetApp.openById(getGlobal('targetid'));
    var tsh = tss.getSheetByName('Sheet1');
    tsh.getRange(tsh.getLastRow() + 1, 2).setValue(v);
    e.range.setValue("FALSE");
  }
}

An installable trigger is required for using openById();

The getGlobal(targetid) function retrieves a spreadsheet id, which can be replaced with the actual id.

I restricted the action to only one sheet and only when the checkbox is set to true. It is then reset to false within the code.

Modifications may be necessary to adapt the code to your needs, as I tend to personalize examples based on my preferences.

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

The Vue computed property is failing to retrieve the data it needs

I'm having trouble with the computed() property not retrieving data. Data was initialized in the created() property. Am I missing something here? Any guidance on how to resolve this issue would be greatly appreciated. const randomPlayers = { temp ...

How to retrieve the content/value from a textfield and checkbox using HTML

I'm encountering an issue with my HTML code where I am unable to extract data from the HTML file to TS. My goal is to store all the information and send it to my database. Here is a snippet of the HTML: <h3>Part 1 : General Information</h3 ...

The button labeled "issett" is malfunctioning

Hey there, so I've created a registration form using jQuery and PHP that validates user input in real-time as they type. Once all the information is correct, I want to allow the user to submit the form. My plan is to write an if statement that checks ...

width of the cells within the grid table

What is the best way to ensure the width alignment of cells in both the header and main section? I have highlighted the correct option in the image with green checkmarks. Check out the image here. Here is my example and solution: View the code on CodePen. ...

combine blank cells in table generated with vuejs

I am attempting to display a table of students where each column represents a subject, and underneath each column are the names of the students who failed in that particular subject. The challenge I am facing is that my data is structured in rows instead o ...

I am having trouble getting the graph to display using PHP and MySQL on Fusion Charts

I am looking to create a line graph based on data from my database. This is my first time working with Fusion Charts, so I followed the instructions in their documentation for dynamic charts. Here is the code from my PHP page: <?php include("Includes/F ...

Tips for integrating NPM Modules with Flask

As I deploy my Python application with Flask using the render_template() function onto a webpage, I am also attempting to integrate some JavaScript modules using npm. Even though I have installed the necessary modules in the static folder along with all my ...

The Distribution and Subscription of Meteor Collections

Today has been a challenging day for me. I have encountered several related topics while trying to solve my issue, but unfortunately, I haven't been able to fix it yet. Being relatively new to Meteor, I have removed autopublish and am not sure if I am ...

Error 400 encountered when executing Jquery's Ajax function

I'm currently utilizing Jquery alongside Spring MVC. In my project, I have an index.jsp: <html> <head> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/cs ...

Deciding on excluding empty key:value pairs from an object for various filtering needs

One of the features in my app allows users to filter results by "blood group" and "city", along with other areas. The information is retrieved from a database using Axios for Vuejs, incorporating query strings within the URL. For example: http://example.co ...

Send FormData as JSON object array using ReactStrap Form and Express server

Currently in the process of learning the MERN stack, I find myself navigating through React and Express for the first time. One of my tasks involves utilizing an API that I had previously set up to update JSON data using React. To accomplish this, I' ...

Tips on maintaining the position of images in Fabric.js

Currently, I am working on image processing using fabric js. Dealing with large images requires me to save copies of canvases after processing to enable faster display next time using jQuery's id.show feature. However, my goal is to render images in t ...

Automatic line breaks within a JavaScript code can be achieved by using

I need help formatting this text: hello everyone. My name is PETER. hahahah ahahah .... If I have a fixed width, how can I automatically line break the text to look like this: hello everyone. My name is PETER. hahahah ahahah ...

Is there a way to determine which radio button has been chosen using jQuery?

I'm trying to retrieve the value of the selected radio button using jQuery. Can anyone help with this? Currently, I am able to target all radio buttons like so: $("form :radio") But how can I determine which one is actually selected? ...

Exploring Typescript ENUMs

I need to save a list of alpha-numeric options as an ENUM in Typescript. Here is an example list: 1.134/2394 x 3-xyz 2.123/234 y 3-ery 3.345/99 t 4-red 4.4.1hv 3 secondary 5.2.51hv 3 secondary 6.1.61hv 3 secondary If anyone has thoughts on how to ...

A guide to creating a reference between two tables using the hasOne method in sequelize.js

After generating 3 models using sequelize-auto, let's take a look at them: sequelize.define('users', { id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: ...

ng-click="showInventory()" onClick="currentTemplate='/inventory.html'" Not

I'm facing an issue with my menu list. When I apply the ng-repeat directive, it seems to not work properly. However, when I remove the ng-repeat, everything functions as expected. <div class="reports_header_tabs_holder"> <span ng-repea ...

Alert displayed at the center of the browser when the value surpasses the specified number

My webpage retrieves SNMP data using PHP and displays it with HTML, color-coding the values. I want to add a pop-up alert when a value exceeds a certain number. I have attempted different jQuery solutions without success. The PHP code to get the value: ...

Show the content of a list from a different URL on a webpage using HTML with the

My current task involves retrieving JSON data using Jquery and then displaying the names in a simple HTML list. Typically, the JSON files I work with have a straightforward format like: [ {a:1,b:2},{a:3,b:4}] However, this time, the JSON file is hosted ...

Can someone help me identify the table rows that are adjacent to a dropped row in a jQueryUI Sortable setup?

My current setup involves using the jQueryUI Sortable plugin on a table, and thankfully everything appears to be functioning correctly. Both the HTML and JavaScript are passing validation. However, I am faced with the challenge of finding a way to identi ...