Google sheets song request


Joined
Jun 14, 2018
Messages
42
Reaction score
0
hi all i'm using google sheets
for my song requests
but at the moment i have a pop up box
stating Requested: Artist: | Song: then whatever song is in my playlist
but i would the popup box to have a dedication box within in and the persons name
with the words succesfully requested?

here's the script

Code:
<!DOCTYPE html>
<html>

<head>
  <!--Import Google Icon Font-->
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <!--Import materialize.css-->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

  <!--Let browser know website is optimized for mobile-->
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<body>
  <div class="container">
    <div class="row">
      <div class="col s12 m6">
        <div class="card blue-grey darken-1">
          <div class="card-content white-text">
            <span class="card-title" id="title"></span>
            <p id="song"></p>
          </div>
          <div class="card-action">
            <button class="btn waves-effect waves-light" type="button" value="run" id="btn" onClick="requestSong()">Request
            <i class="material-icons right">music_note</i>
            </button>
            <p id="check"></p>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!--JavaScript at end of body for optimized loading-->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
  <script>
    window.setInterval(function() {
      google.script.run.withSuccessHandler(getCrrentRowData).getCrrentRowData();
    }, 700);

    var artist = document.getElementById("title")
    var song = document.getElementById("song")
    var artistValue;
    var songValue;


    function requestSong(){
      console.log('Pressed button')
      const data = {
        artist: artistValue,
        song: songValue
      }
      google.script.run.sendEmail(data)
    }

    function getCrrentRowData() {
      google.script.run
        .withSuccessHandler(function (result) {
          artist.innerText = result.artist;
          song.innerText = result.song;
          artistValue = result.artist;
          songValue = result.song;
      }).getCrrentRowData();
    }
  </script>
</body>

</html>


JavaScript:
const playlistSheet = 'playlist'
const email = '[email protected]'

function showSidebar(){
  const ui = SpreadsheetApp.getUi()
  const html = HtmlService.createHtmlOutputFromFile("index.html")
  html.setTitle("Request song")
  ui.showSidebar(html)
}

function onOpen(e) {
  SpreadsheetApp.getUi().createMenu('Sidebar')
    .addItem('Open', 'showSidebar')
    .addToUi();
}

function sendEmail(obj){
  const {artist, song} = obj
  console.log(obj)
  const time = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "HH:MM:SS")
  const body = `New request:\n\nArtist: ${artist}\nSong: ${song}`
  GmailApp.sendEmail(email, `New request: ${time}`, body)
  SpreadsheetApp.getUi().alert(`Requested: Artist: ${artist} | Song: ${song}`)
}

function getCrrentRowData(){
  const ss = SpreadsheetApp.getActiveSpreadsheet()
  const activeSheet = ss.getActiveSheet()
  if(activeSheet.getName() != playlistSheet) { return }

  const row = activeSheet.getActiveRange().getRow()
  const [ artist, song ] = activeSheet.getRange(row,1,1,2).getValues().flat()
  return {artist, song}

}

function sleep(){
  Utilities.sleep(1500)
  return;
}

could anyone please help me
 
Ad

Advertisements

Joined
Nov 13, 2020
Messages
140
Reaction score
23
I can't get this to run on my machine. Think I need google scripts to run it. I don't want to learn google scripts. Do they have a place where you can seek help there where the people know google scripts?
 
Ad

Advertisements

Joined
Jan 24, 2022
Messages
30
Reaction score
1
Yes actually, I was looking at the program but cannot run it on my computer. Maybe I can run my own code and help you out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top