Remove Duplicates

Hi everyone,

I have a problem with duplicate uniqueid. So my system used adalo as one of the platform to pass value to google sheets and appsheet will use google sheet as the database.
The issue is adalo keep sending duplicates to google sheet because user pressing submit button multiple times hence affecting appsheet view as well. I tried using formula to recognize duplicate and want to filter using slice but it will only work on the row once the row is updated which is not reliable since adalo only send data to google sheet and not appsheet directly.

Does anyone have any idea on what I should do to remove these duplicates?

Solved Solved
0 7 381
1 ACCEPTED SOLUTION

I gave up looking on adalo and make I just tried again using appsheet and it works. I just used apps script to check on for 2 column on rows having same data will just change the data to duplicate instead. below is what i used.

function checkAndMarkDuplicatesTwoColumns() {
  // Replace with your actual spreadsheet ID or URL
  var spreadsheetId = 'SHEET ID'; // or use openByUrl
  // var spreadsheetUrl = 'YOUR_SPREADSHEET_URL'; // Uncomment this if using URL instead

  // Open the spreadsheet by ID or URL
  var spreadsheet = SpreadsheetApp.openById(spreadsheetId); // or use openByUrl(spreadsheetUrl)
 
  // Specify the sheet name you want to work with (replace 'Sheet1' with your actual sheet name)
  var sheet = spreadsheet.getSheetByName('Work Order'); // Use the name of the sheet

  if (!sheet) {
    Logger.log('Sheet not found!');
    return;
  }
 
  // Set the column indices to check for duplicates (e.g., 1 = Column A, 2 = Column B)
  var columnA = 1; // Column A
  var columnB = 2; // Column B
 
  // Set the column index for the "status" column (e.g., 3 = Column C)
  var statusColumn = 3; // Change this to the column where you want to mark 'Duplicate' (e.g., 3 for Column C)

  // Get all the values from the columns to check (skip the first row if it has headers)
  var dataRangeA = sheet.getRange(2, columnA, sheet.getLastRow() - 1).getValues(); // Column A values
  var dataRangeB = sheet.getRange(2, columnB, sheet.getLastRow() - 1).getValues(); // Column B values

  // Object to track seen combinations
  var valueMap = {};
 
  // Loop through the data to find duplicates based on both Column A and Column B
  for (var i = 0; i < dataRangeA.length; i++) {
    var currentValueA = dataRangeA[i][0]; // Get the value from Column A
    var currentValueB = dataRangeB[i][0]; // Get the value from Column B

    // Create a combined key for both Column A and Column B values
    var combinedValue = currentValueA + "-" + currentValueB;

    // Check if the combined key has already been encountered
    if (valueMap[combinedValue]) {
      // If it's a duplicate, mark 'Duplicate' in the status column
      sheet.getRange(i + 2, statusColumn).setValue('Duplicate');
    } else {
      // If it's not a duplicate, store the combined value in the map
      valueMap[combinedValue] = true;
    }
  }
}

View solution in original post

7 REPLIES 7
Top Labels in this Space