0

May i ask how to create button in google slide using app script

Here is my sample code

function pickName() {
  // Step 2: Retrieve names from Google Sheets
  var sheet = SpreadsheetApp.openById("1T8gNoGYHOmDh09pprjBzKN9F1hB3EuetGIKndUs_1LU").getSheetByName("Sheet1");
  var names = sheet.getRange("A1:A6").getValues();
  names = names.filter(String).flat(); // Remove empty values

  // Step 3: Generate a random number
  var randomIndex = Math.floor(Math.random() * names.length);

  // Step 4: Get the selected name
  var selectedName = names[randomIndex];

  //Step 5: Update the button text
  var pp1 = SlidesApp.openById("1Yh2_loEzDxZkLwpuo9oRsJbItLjKjd2cB2ASJLO9_h0");
  var slide1 =  SlidesApp.getActivePresentation().getSlides()[0];
  var button = slide1.getPageElementById("g181ededb6a0_0_0");
  button.updateText(selectedName);
  button.addClickEvent(pickName());
}
Bry
  • 1
  • 3
  • I have to apologize for my poor English skill. Unfortunately, I cannot imagine your expected result from `How to create button in google slide using app script`. Can I ask you about the detail of the current issue of your script and your goal? – Tanaike Jan 24 '23 at 01:53
  • By the way, there is no method of `getId` in Class Shape. [Ref](https://developers.google.com/apps-script/reference/slides/shape) So, I cannot also understand `button.updateText(selectedName);` and `button.addClickEvent(pickName());`. From this situation, I'm worried that you might have miscopied your current script. How about this? – Tanaike Jan 24 '23 at 01:59
  • noted i edit my post my expected result was to create a name picker in google slide using app script, Thanks – Bry Jan 24 '23 at 02:01
  • 1
    Thank you for replying. I would like to support you. But, I have to apologize for my poor English skill, again. Unfortunately, from `noted i edit my post`, I cannot still understand your question. But I would like to try to understand it. When I could correctly understand it, I would like to think of a solution. I would be grateful if you can forgive my poor English skill. – Tanaike Jan 24 '23 at 02:06
  • Hi. You said that you want to "create a name picker in google slide using app script". This isn't what you described in your question Title or Body. Would you please edit your question Title AND Body to describe EXACTLY what you are trying to achieve, and describe what you understand a "name picker" to be and do. Would you also summarise your research before submitting this question particularly as all the posts on StackOverflow indicate that "There isn't a way to assign a script to a button in Google Slides in the same way as there is in Google Sheets." – Tedinoz Jan 24 '23 at 04:16

0 Answers0