Google Appscript append data from Queryimport to FK the Col C needs to be checked and appended in Col D no duplication

32 views Asked by At

`` This is my function details any help would be appreciated

    **function calling**
    function appendDataIfNotExists() {
     var ss = SpreadsheetApp.getActiveSpreadsheet();
     var sheet1 = ss.getSheetByName("QueryImport");
     var sheet2 = ss.getSheetByName("FK");
     
     var data1 = sheet1.getRange("C6:C").getValues();
     var data2 = sheet2.getRange("D6:D").getValues();
     
     var newData = [];
     **Traversing**
     for (var i = 0; i < data1.length; i++) {
       var valueToAppend = data1[i][0];
       **appending**
       // Skip empty or null values
       if (valueToAppend !== null && valueToAppend !== "" && valueToAppend !== "Ppppppppp") {
         if (!data2.some(function(row) { return row[0] === valueToAppend })) {
           newData.push([valueToAppend]);
         }
       }
     }
     
     if (newData.length > 0) {
       sheet2.getRange(sheet2.getLastRow() + 1, 4, newData.length, 1).setValues(newData);
     }

``/////////////////////////////////////////////////////////////////////////////////////

0

There are 0 answers