0
votes

I`m trying to add "Search Item" option in the tool bar. Basically, I have 6 different tabs in the same google sheet, but the # of items in each sheet is too many that users may not be able to find.

Is there way to add such tool in tool bar using Google sheet Script?

https://docs.google.com/spreadsheets/d/1lbfbMUhwKGG0CJ1tJuXVmwCRPAox_1dIATffhKVjkQM/edit?usp=sharing

Above is the link to the sample data

The data is generated from API for ad server system

In my real data, that "Creative" column has about > 1000 unique entries

Is there potentially, way to put option in a toolbar that does the "creative" search job, that can tell us creative "c6" was found in "first" tab, second row..

But search those items in only the "unhidden" tab

I`m not sure where I should start this with.. given the multiple tabs

Can someone please provide me suggestions?

1
In order to correctly your situation, can I ask you about your goal? 1. When I saw your shared Spreadsheet,I thought that you might want to search the rows from each column "A" (Creative) using a value. Is my understanding correct? 2. What is the tool bar you think? 3. In your tag, "Javascript" is used. Do you want to achieve this using Javascript which is not Google Apps Script? 4. Can you provide your current script? 5. What is the tab of "RAW"? In your actual Spreadsheet, is the tab you don't want to search included? I apologize for my poor English skill.Tanaike
Hello Tanaike, oh you again!! I don`t understand when you say poor English skill when your sentence is perfect, anyways I remember you! you answered my previous question and was able to accomplish the task perfectly... :) So for this task, 1) I am trying to search items in "Creative" column and return that actual item in "Creative" column + Impression + Click values (numeric values adjacent to that creative basically..) 2) Tool bar as in one of those tool bars that show up at the top of Google Sheet.(Something right next to "Data", "Tools") 3) No, through Google Sheet App Script!StarSpirit_2000
To be continued.. 5) RAW is the raw data that is the origin for all the separate tabs there. (I didnt include it here) And yes, that is the tab I dont want to be searched since that is just raw data. 4) For the script, frankly speaking, I haven`t written specifically for this tool-bar task, but i have the API call, raw data transformation and split into the separate tab code.. Should we look into this code as well? I really have no clue how I should start for creating this tool-bar...StarSpirit_2000
Thank you for quick reply. I understood about your goal as the following flow. 1. Input a search value. You want to run Google Apps Script by the menu bar. 2. Search the column "A" for each sheet using the search value, and when the searched value is found at the column "A", it retrieves the row. There are sheets you don't want to use for searching. Can you tell me whether my understanding is correct? And as an additional question, where do you want to show the searched results?Tanaike
Yes!! That is 100% correct. But for the results part, a few modifications.. so the results will include a) which tab that item is included in b) associated impression values / click values from each tab.StarSpirit_2000

1 Answers

1
votes
  • Input a search value.
    • You want to run Google Apps Script by the menu bar.
  • Search the column "A" for each sheet using the search value, and when the searched value is found at the column "A", it retrieves the row.
    • There are sheets you don't want to use for searching.
  • You want to show the result as follows.

    Creative "C6" was found in "Second", "fifth" tab
    Second Tab: Impression:100 / Click:100
    Fifth Tab: Impression:100 / Click:100
    

I understood like above. If my understanding is correct, how about this sample script? Please think of this as just one of them.

Flow:

  1. When Spreadsheet is opened, the custom menu is added.
  2. Run the script from "Show prompt" of the custom menu. By this, a dialog box is opened.
  3. Input a search text to the text input field, and click "ok" button.
  4. At the script, the rows are searched with TextFinder using the inputted search text.
  5. Show the result by a dialog box as a sample.

Sample script:

Before you run the script, please set the sheet name to sheets.

function onOpen() {
  SpreadsheetApp.getUi()
      .createMenu('Custom Menu')
      .addItem('Show prompt', 'showPrompt')
      .addToUi();
}

function showPrompt() {
  // Please set the sheet name you want to use for searching.
  var sheets = ["first", "second", "third", "fourth", "fifth", "sixth"];

  var ui = SpreadsheetApp.getUi();
  var res = ui.prompt('Sample', 'Input search text:', ui.ButtonSet.OK_CANCEL);
  var button = res.getSelectedButton();
  if (button == ui.Button.OK) {
    var findText = res.getResponseText();
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var header = "Creative \"" + findText + "\" was found in ";
    var values = "";
    var object = sheets.reduce(function(obj, sheetName, i) {
      var sheet = ss.getSheetByName(sheetName);
      var textFinder = sheet.createTextFinder(findText);
      var searchedRows = textFinder.findAll().reduce(function(ar, e) {
        if (e.getColumn() == 1) {
          var row = sheet.getRange(e.getRow(), 1, 1, sheet.getLastColumn()).getValues()[0];
          if (row[0] === findText) {
            ar.push(row);
            header += '"' + sheetName + '"' + (i == sheets.length - 1 ? " tab\n" : ", ");
            values += sheetName + " Tab: Impression:" + row[1] + " / Click:" + row[2] + "\n";
          }
        }
        return ar;
      }, []);
      if (searchedRows.length > 0) obj[sheetName] = searchedRows;
      return obj;
    }, {});
    Logger.log(object);
    ui.alert(header + values);
  }
}

enter image description here

enter image description here

Note:

  • This is a sample script. please modify this for your situation.

References:

Edit:

  • When the searched text was not found, you want to show "The creative you just searched for does not exist, please go back and check if there is any typo!".

In order to reflect your above request to the script, please modify above script as follows.

From:

ui.alert(header + values);

To:

if (Object.keys(object).length > 0) {
  ui.alert(header.slice(0, -2) + " tab\n" + values);
} else {
  ui.alert("The creative you just searched for does not exist, please go back and check if there is any typo!");
}