Home > Software design >  ALTERNATIVE TO APPENDROW OR HOW TO DUPLICATE ROWS TO SPREADSHEET
ALTERNATIVE TO APPENDROW OR HOW TO DUPLICATE ROWS TO SPREADSHEET

Time:08-26

I have the following code that can send the inputs values to a row in Google SpreadSheet. I want to send the values twice to the same spreadsheet (firts time on one row, the second time on the next row). I have copy the function that sends the values to the spreadsheet (with some changes to not duplicate the function´s name). But I can only pass one time the values. i think that the seocnd time the function crashes ( thats what I think). Do to some policies on software, I can only use pure JavaScript. Can I use an alternative to send the values to the same spreadsheet on separate rows? What alternative would you all recommend? I am sharing the Code.gs and HTML scripts. Thanks in advance.

HTML


  <form> 
   <table>
    <td>
          <tr>
           <td><label id="Date_01">Date</label></td>
           <td><input type="date" id="idDate"></td>
          </tr>
            <br>
          <tr>
           <td><label id="LabelAccount">Vendor´s Account</label></td>
           <td><select type="text" id="idAccount">
            <option>A0011</option>
            <option>A0022</option>
            <option>A0033</option>
            </select></td>
          </tr>
            <br>
          <tr>
           <td><label id="LabelVendorID">Vendor´s Identification Number</label></td>
           <td><select type="text" id="idVendor">
            <option>ID0044</option>
            <option>ID0055</option>
            <option>ID0066</option>
            </select></td>
          </tr>
          <br>
          <tr>
           <td><label id="LabelBranch">Vendor´s Branch</label></td>
            <td><select type="text" id="idBranch">            
            <option>BRANCH001</option>
            <option>BRANCH002</option>
            <option>BRANCH003</option>
            </select></td>
          </tr>  
     </td>
  </table> 
 </form>
     
  <form> 
<table>
<td>
      <tr>
            <caption style="color:#ffffff;font-family:arial black;font-size:15px; border:0px solid #1f3f79; background-color: #004481;">DETAILS</caption>
      </tr>     
          <tr>
           <td><label id="Label1000_01">DOC 1000_01</label>
           <br>
           <input type="text" id="id1000_01"></td>
           <td><label id="Label1000_02">DOC 1000_02</label>
           <br>
           <input type="text" id="id1000_02"></td>
           <td><label id="Label1000_03">DOC 1000_03</label>
           <br>
           <input type="text" id="id1000_03"></td>
           <td><label id="Label1000_04">DOC 1000_04</label>
           <br>
           <input type="text" id="id1000_04"></td>
           <td><label id="Label1000_05">DOC 1000_05</label>
           <br>
           <input type="text" id="id1000_05"></td>
         </tr>  
         <tr>
           <td><label id="Label2000_01">DOC 2000_01</label>
           <br>
           <input type="text" id="id2000_01"></td>
           <td><label id="Label2000_02">DOC 2000_02</label>
           <br>
           <input type="text" id="id2000_02"></td>
           <td><label id="Label2000_03">DOC 2000_03</label>
           <br>
           <input type="text" id="id2000_03"></td>
           <td><label id="Label2000_04">DOC 2000_04</label>
           <br>
           <input type="text" id="id2000_04"></td>
           <td><label id="Label2000_05">DOC 2000_05</label>
           <br>
           <input type="text" id="id2000_05"></td>
         </tr>           
         <tr>
           <td><label id="Label3000_01">DOC 3000_01</label>
           <br>
           <input type="text" id="id3000_01"></td>
           <td><label id="Label3000_02">DOC 3000_02</label>
           <br>
           <input type="text" id="id3000_02"></td>
           <td><label id="Label3000_03">DOC 3000_03</label>
           <br>
           <input type="text" id="id3000_03"></td>
           <td><label id="Label3000_04">DOC 3000_04</label>
           <br>
           <input type="text" id="id3000_04"></td>
           <td><label id="Label3000_05">DOC 3000_05</label>
           <br>
           <input type="text" id="id3000_05"></td>
         </tr>          
         <tr>
           <td><label id="Label4000_01">DOC 4000_01</label>
           <br>
           <input type="text" id="id4000_01"></td>
           <td><label id="Label4000_02">DOC 4000_02</label>
           <br>
           <input type="text" id="id4000_02"></td>
           <td><label id="Label4000_03">DOC 4000_03</label>
           <br>
           <input type="text" id="id4000_03"></td>
           <td><label id="Label4000_04">DOC 4000_04</label>
           <br>
           <input type="text" id="id4000_04"></td>
           <td><label id="Label4000_05">DOC 4000_05</label>
           <br>
           <input type="text" id="id4000_05"></td>
         </tr> 
         <tr>
           <td><label id="Label5000_01">DOC 5000_01</label>
           <br>
           <input type="text" id="id5000_01"></td>
           <td><label id="Label5000_02">DOC 5000_02</label>
           <br>
           <input type="text" id="id5000_02"></td>
           <td><label id="Label5000_03">DOC 5000_03</label>
           <br>
           <input type="text" id="id5000_03"></td>
           <td><label id="Label5000_04">DOC 5000_04</label>
           <br>
           <input type="text" id="id5000_04"></td>
           <td><label id="Label5000_05">DOC 5000_05</label>
           <br>
           <input type="text" id="id5000_05"></td>
         </tr> 
         <tr>
           <td><label id="Label6000_01">DOC 6000_01</label>
           <br>
           <input type="text" id="id6000_01"></td>
           <td><label id="Label6000_02">DOC 6000_02</label>
           <br>
           <input type="text" id="id6000_02"></td>
           <td><label id="Label6000_03">DOC 6000_03</label>
           <br>
           <input type="text" id="id6000_03"></td>
           <td><label id="Label6000_04">DOC 6000_04</label>
           <br>
           <input type="text" id="id6000_04"></td>
           <td><label id="Label6000_05">DOC 6000_05</label>
           <br>
           <input type="text" id="id6000_05"></td>
         </tr> 
         <tr>
           <td><label id="Label7000_01">DOC 7000_01</label>
           <br>
           <input type="text" id="id7000_01"></td>
           <td><label id="Label7000_02">DOC 7000_02</label>
           <br>
           <input type="text" id="id7000_02"></td>
           <td><label id="Label7000_03">DOC 7000_03</label>
           <br>
           <input type="text" id="id7000_03"></td>
           <td><label id="Label7000_04">DOC 7000_04</label>
           <br>
           <input type="text" id="id7000_04"></td>
           <td><label id="Label7000_05">DOC 7000_05</label>
           <br>
           <input type="text" id="id7000_05"></td>
         </tr> 
         <tr>
           <td><label id="Label8000_01">DOC 8000_01</label>
           <br>
           <input type="text" id="id8000_01"></td>
           <td><label id="Label8000_02">DOC 8000_02</label>
           <br>
           <input type="text" id="id8000_02"></td>
           <td><label id="Label8000_03">DOC 8000_03</label>
           <br>
           <input type="text" id="id8000_03"></td>
           <td><label id="Label8000_04">DOC 8000_04</label>
           <br>
           <input type="text" id="id8000_04"></td>
           <td><label id="Label8000_05">DOC 8000_05</label>
           <br>
           <input type="text" id="id8000_05"></td>
         </tr>
         <tr>
           <td><label id="Label9000_01">DOC 9000_01</label>
           <br>
           <input type="text" id="id9000_01"></td>
           <td><label id="Label9000_02">DOC 9000_02</label>
           <br>
           <input type="text" id="id9000_02"></td>
           <td><label id="Label9000_03">DOC 9000_03</label>
           <br>
           <input type="text" id="id9000_03"></td>
           <td><label id="Label9000_04">DOC 9000_04</label>
           <br>
           <input type="text" id="id9000_04"></td>
           <td><label id="Label9000_05">DOC 9000_05</label>
           <br>
           <input type="text" id="id9000_05"></td>
         </tr> 
 </table>
  </form>
</td>

<script>
    function registerFullOperation(){
    var RegisterOps = {};
    
    RegisterOps.idDate = document.getElementById("idDate").value;
    RegisterOps.idAccount = document.getElementById("idAccount").value;
    RegisterOps.idVendor = document.getElementById("idVendor").value;
    RegisterOps.idBranch = document.getElementById("idBranch").value;
    RegisterOps.id1000_01 = document.getElementById("id1000_01").value;
    RegisterOps.id1000_02 = document.getElementById("id1000_02").value;
    RegisterOps.id1000_03 = document.getElementById("id1000_03").value;
    RegisterOps.id1000_04 = document.getElementById("id1000_04").value;
    RegisterOps.id1000_05 = document.getElementById("id1000_05").value;
    RegisterOps.id2000_01 = document.getElementById("id2000_01").value;
    RegisterOps.id2000_02 = document.getElementById("id2000_02").value;
    RegisterOps.id2000_03 = document.getElementById("id2000_03").value;
    RegisterOps.id2000_04 = document.getElementById("id2000_04").value;
    RegisterOps.id2000_05 = document.getElementById("id2000_05").value;
    RegisterOps.id3000_01 = document.getElementById("id3000_01").value;
    RegisterOps.id3000_02 = document.getElementById("id3000_02").value;
    RegisterOps.id3000_03 = document.getElementById("id3000_03").value;
    RegisterOps.id3000_04 = document.getElementById("id3000_04").value;
    RegisterOps.id3000_05 = document.getElementById("id3000_05").value;
    RegisterOps.id4000_01 = document.getElementById("id4000_01").value;
    RegisterOps.id4000_02 = document.getElementById("id4000_02").value;
    RegisterOps.id4000_03 = document.getElementById("id4000_03").value;
    RegisterOps.id4000_04 = document.getElementById("id4000_04").value;
    RegisterOps.id4000_05 = document.getElementById("id4000_05").value;
    RegisterOps.id5000_01 = document.getElementById("id5000_01").value;
    RegisterOps.id5000_02 = document.getElementById("id5000_02").value;
    RegisterOps.id5000_03 = document.getElementById("id5000_03").value;
    RegisterOps.id5000_04 = document.getElementById("id5000_04").value;
    RegisterOps.id5000_05 = document.getElementById("id5000_05").value;
    RegisterOps.id6000_01 = document.getElementById("id6000_01").value;
    RegisterOps.id6000_02 = document.getElementById("id6000_02").value;
    RegisterOps.id6000_03 = document.getElementById("id6000_03").value;
    RegisterOps.id6000_04 = document.getElementById("id6000_04").value;
    RegisterOps.id6000_05 = document.getElementById("id6000_05").value;
    RegisterOps.id7000_01 = document.getElementById("id7000_01").value;
    RegisterOps.id7000_02 = document.getElementById("id7000_02").value;
    RegisterOps.id7000_03 = document.getElementById("id7000_03").value;
    RegisterOps.id7000_04 = document.getElementById("id7000_04").value;
    RegisterOps.id7000_05 = document.getElementById("id7000_05").value;
    RegisterOps.id8000_01 = document.getElementById("id8000_01").value;
    RegisterOps.id8000_02 = document.getElementById("id8000_02").value;
    RegisterOps.id8000_03 = document.getElementById("id8000_03").value;
    RegisterOps.id8000_04 = document.getElementById("id8000_04").value;
    RegisterOps.id9000_01 = document.getElementById("id9000_01").value;
    RegisterOps.id9000_02 = document.getElementById("id9000_02").value;
    RegisterOps.id9000_03 = document.getElementById("id9000_03").value;
    RegisterOps.id9000_04 = document.getElementById("id9000_04").value;
    RegisterOps.id9000_05 = document.getElementById("id9000_05").value;
    google.script.run.registerFullOperation(RegisterOps); 
    }       
</script>

   <button id="idButton" onclick="registerFullOperation()">REGISTER</button> 
  

GS

var ss = SpreadsheetApp.openByUrl("URL");
var sheetOps = ss.getSheetByName("SHEET 1");

  function registerFullOperation(RegisterOps){
sheet.appendRow([RegisterOps.idDate,RegisterOps.idAccount,RegisterOps.idVendor,RegisterOps.idBranch,RegisterOps.id1000_01,RegisterOps.id1000_02,RegisterOps.id1000_03,RegisterOps.id1000_04,RegisterOps.id1000_05,RegisterOps.id2000_01,RegisterOps.id2000_02,RegisterOps.id2000_03,RegisterOps.id2000_04,RegisterOps.id2000_05,RegisterOps.id3000_01,RegisterOps.id3000_02,RegisterOps.id3000_03,RegisterOps.id3000_04,RegisterOps.id3000_05,RegisterOps.id4000_01,RegisterOps.id4000_02,RegisterOps.id4000_03,RegisterOps.id4000_04,RegisterOps.id4000_05,RegisterOps.id5000_01,RegisterOps.id5000_02,RegisterOps.id5000_03,RegisterOps.id5000_04,RegisterOps.id5000_05,RegisterOps.id6000_01,RegisterOps.id6000_02,RegisterOps.id6000_03,RegisterOps.id6000_04,RegisterOps.id6000_05,RegisterOps.id7000_01,RegisterOps.id7000_02,RegisterOps.id7000_03,RegisterOps.id7000_04,RegisterOps.id7000_05,RegisterOps.id8000_01,RegisterOps.id8000_02,RegisterOps.id8000_03,RegisterOps.id8000_04,RegisterOps.id8000_05,RegisterOps.id9000_01,RegisterOps.id9000_02,RegisterOps.id9000_03,RegisterOps.id9000_04,RegisterOps.id9000_05]);}


SPREADSHEET RESULT

enter image description here

CodePudding user response:

First, the reason the button doesn't work is it should be registerFullOperation()

<button id="idButton" onclick="registerFullOperation()">REGISTER</button>

Secondly, to copy 2 rows

let row = [RegisterOps.idDate,RegisterOps.idAccount,RegisterOps.idVendor,RegisterOps.idBranch,RegisterOps.id1000_01,RegisterOps.id1000_02,RegisterOps.id1000_03,RegisterOps.id1000_04,RegisterOps.id1000_05,RegisterOps.id2000_01,RegisterOps.id2000_02,RegisterOps.id2000_03,RegisterOps.id2000_04,RegisterOps.id2000_05,RegisterOps.id3000_01,RegisterOps.id3000_02,RegisterOps.id3000_03,RegisterOps.id3000_04,RegisterOps.id3000_05,RegisterOps.id4000_01,RegisterOps.id4000_02,RegisterOps.id4000_03,RegisterOps.id4000_04,RegisterOps.id4000_05,RegisterOps.id5000_01,RegisterOps.id5000_02,RegisterOps.id5000_03,RegisterOps.id5000_04,RegisterOps.id5000_05,RegisterOps.id6000_01,RegisterOps.id6000_02,RegisterOps.id6000_03,RegisterOps.id6000_04,RegisterOps.id6000_05,RegisterOps.id7000_01,RegisterOps.id7000_02,RegisterOps.id7000_03,RegisterOps.id7000_04,RegisterOps.id7000_05,RegisterOps.id8000_01,RegisterOps.id8000_02,RegisterOps.id8000_03,RegisterOps.id8000_04,RegisterOps.id8000_05,RegisterOps.id9000_01,RegisterOps.id9000_02,RegisterOps.id9000_03,RegisterOps.id9000_04,RegisterOps.id9000_05,];
let rows = [row,row];
sheetOps.getRange(sheetOps.getLastRow() 1,1,rows.length,rows[0].length).setValues(rows);

However if any of your object properties are a Date, convert to string before passing back to server.

  • Related