Skip to content

populateTierDataImportSheets

populateTierDataImportSheets syncs player data from a central Contract Import sheet out to individual per-tier data import sheets (e.g. "Premier Data Import", "Master Data Import", etc.).

On each run it reads all player rows from Contract Import, then loops through all nine RSC tiers. For each tier, it clears any previously written data from that tier's sheet and re-populates it with only the players whose Tier column matches - writing their Name, RSC ID, Tier, Current MMR, and Contract Status into the first five columns, with eight additional blank columns reserved for static data that gets filled in elsewhere.

The end result is that each tier sheet always has a fresh, filtered snapshot of just its own players pulled from the Contract Sheet.

Sheet Location

How to Use

  1. Open the Google Sheet
  2. Go to Extensions > Apps Script
  3. Paste the code below into the editor
  4. Save and run

Code

function populateTierDataImportSheets() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const contractSheet = ss.getSheetByName("Contract Import");
  const tiers = ["Premier", "Master", "Elite", "Veteran", "Rival", "Challenger", "Prospect", "Contender", "Amateur"];

  const headers = contractSheet.getRange(1, 1, 1, contractSheet.getLastColumn()).getValues()[0];
  const contractData = contractSheet.getRange(2, 1, contractSheet.getLastRow() - 1, contractSheet.getLastColumn()).getValues();

  // Build a column index map
  const colIndex = header => headers.indexOf(header);

  tiers.forEach(tier => {
    const tierSheet = ss.getSheetByName(tier + " Data Import");
    if (!tierSheet) return;

    // Clear previous data (excluding row 1 for headers or formulas)
    const lastRow = tierSheet.getLastRow();
    if (lastRow > 1) {
      tierSheet.getRange(2, 1, lastRow - 1, 13).clearContent();
    }

    // Filter players who match the tier
    const tierPlayers = contractData.filter(row => row[colIndex("Tier")] === tier);

    // Map to: Name, RSC ID, Tier, MMR, Status, StaticData1–8
    const formatted = tierPlayers.map(row => [
      row[colIndex("Player Name")],
      row[colIndex("RSC ID")],
      row[colIndex("Tier")],
      row[colIndex("Current MMR")],
      row[colIndex("Contract Status")],
      "", "", "", "", "", "", "", ""
    ]);

    // Paste into Data Import sheet starting from Row 2
    if (formatted.length > 0) {
      tierSheet.getRange(2, 1, formatted.length, 13).setValues(formatted);
    }
  });
}

Notes