Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
650 views
in Technique[技术] by (71.8m points)

google apps script - Create a Dialog box with custom buttons and Links

So I have an internal emailing list that I want to subscribe new employees to and unsubscribe employees that have left. I'm using a google sheet with a check box to do this. Mainly because this sheet is already used in the HR process, so it's easy to remember to do.

When the check the box is checked I want a dialog box to pop up with a buttons that says Subscribe and Unsubscribe. These buttons are linked to locations within the emailing tool that allows people to subscribe or unsunscribe.

The scribe I have at the moment is

    var result = ui.alert
  (
     'What would you like to do?',
     'Subscribe a new Employee or' + "
" + 'Unsubcribe an employee thats left',
      ui.ButtonSet.Subscribe_Unsubscribe
  );

  if (result == ui.Button.Subscribe) 
  {
    
  }else
  {
     ui.alert('Employee has been removed from the internal mailing list');
   }
}

I'm not sure how if by changing the button set names work this way and I dont know how to assign a link to the buttons either.

Looking forward to your responses!!!

question from:https://stackoverflow.com/questions/65919382/create-a-dialog-box-with-custom-buttons-and-links

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Step 1:

First you would need to create an installable trigger that would execute a function in GAS whenever a cell is edited.

You can find an explanation / reference on Installable Triggers here:

Installable Triggers

Why installable triggers? Because you would need to connect to an email service, which requires authorization.

Sample Code:

/**
 * Creates a trigger for when a spreadsheet is edited.
 */
function createSpreadsheetEditTrigger() {
  var ss = SpreadsheetApp.getActive();
  ScriptApp.newTrigger('myFunction')
      .forSpreadsheet(ss)
      .onEdit()
      .create();
}

Step 2:

To create custom dialog boxes you need to create the HTML file from scratch in GAS, the IDE allows you to create HTML files from the menu.

Then in your script you would need to use getUi().showModalDialog to display the dialog box.

I have some sample code in a Stack Overflow post here: Stack Overflow

Note that the HTML would need both onclick="google.script.run" and onclick="google.script.host.close()" parameters to execute functions within Apps Script.

References:

showModalDialog()

Templated HTML

Communication between HTML and Apps Script


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...