0
votes

I'm trying to create a custom browser message which displays with text, which you can see below, and also has the ability to click a button saying, "Ok" and another button saying, "Take me to he guide" which when is clicked, opens up another tab with the guide on.

Here is my current code:

 function onEdit(e) {
  var cell = e.range;
  var cellColumn = cell.getColumn();
  var cellSheet = cell.getSheet().getName();
  var cellValue = e.value;
  var sheet = "System_Info";   

  if (cellSheet !== sheet) {
  if (cellColumn === 4 || cellColumn === 5) {
    if (cellValue === "PT1 - Induction Training") {
      Browser.msgBox('Course Information', "PT1 - Induction Training:\\n\\nType: Theory \\n\\nTime Needed: 15-20 Minutes\\n\\n Learning Resource/Manual: BBACT, Forum Post: Rules for Officers", Browser.Buttons.YES_NO);  //Add the course name and the message that I want to popup. Course name should be exactly the same as in the list (case sensitive)
    } 

    else if (cellValue === "PT2 - Traffic & Communications - Part 1") {
      Browser.msgBox("PT2 - Traffic & Communications - Part 1 - Starting a Patrol/Loadouts: \\n\\nType: Practical \\n\\nTime Needed: 15-20 Minutes\\n\\n Learning Resource/Manual: PT2 Guide \\n Section: 1, 2");  //// add as many "else if" conditions as you want"
    } else if (cellValue === "PT2 - Traffic & Communications - Part 2") {
      Browser.msgBox("PT2 - Traffic & Communications - Part 2 - Checkpoints: \\n\\nType: Practical \\n\\nTime Needed: 40-60 Minutes\\n\\n Learning Resource/Manual: PT2 Guide \\n Section: 4");   
    } else if (cellValue === "PT2 - Traffic & Communications - Part 3") {
      Browser.msgBox("PT2 - Traffic & Communications - Part 3 - Communications & Navigation: \\n\\nType: Practical & Theory (Still required to be on the server) \\n\\nTime Needed: 15-20 Minutes\\n\\n Learning Resource/Manual: PT2 Guide \\n Section: 5, 6, 7");   
    } else if (cellValue === "PT2 - Traffic & Communications - Part 4") {
      Browser.msgBox("PT2 - Traffic & Communications - Part 4 - Faction Relations: \\n\\nType: Theory \\n\\nTime Needed: 15-20 Minutes\\n\\n Learning Resource/Manual: PT2 Guide \\n Section: 8");    
    } else if (cellValue === "PT3 - Officer Advancement - Part 1") {
      Browser.msgBox("PT3 - Officer Advancement - Part 1: \\n\\nType: Theory \\n\\nTime Needed: 20-25 Minutes\\n\\n Learning Resource/Manual: BBACT, Forum Post: Rules for Officers, Forum Post: Sergeant Rules and Regulations, PT2 Guide");   
    } else if (cellValue === "PT3 - Officer Advancement - Part 2") {
      Browser.msgBox("PT3 - Officer Advancement - Part 2: \\n\\nType: Practical \\n\\nTime Needed: 70 Minutes (1 Hour, 10 Minutes)\\n\\n Learning Resource/Manual: NONE, You are taught in-game.");   
    } else if (cellValue === "PT4 - Air Support") {
      Browser.msgBox("PT4 - Air Support: \\n\\nType: Practical \\n\\nTime Needed: 15-25 Minutes\\n\\n Learning Resource/Manual: PT4 Guide");   
    } else if (cellValue === "PT5 - Interceptors") {
      Browser.msgBox('Course Information',"PT5 - Interceptors: \\n\\nType: Practical \\n\\nTime Needed: 25-35 Minutes\\n\\n Learning Resource/Manual: PT5 Guide"); 
    } else if (cellValue === "Planning to Attend") {
      Browser.msgBox('Course Information',"You have chosen to attend this time. However, if you cannot attend training for what ever reason, please select the option, Sorry Can't Make It!");
    } else if (cellValue === "Sorry Can't Make It!") {
      Browser.msgBox('Course Information',"You have chosen not to attend this time. Please add a comment into the cell stating why you couldn't attend. It would also help if you could contact the instructor stating that you cannot attend.");
    } else if (cellValue === "PT1 - Induction Training - Review") {
      Browser.msgBox('Course Information',"This course is for people who have been instructed to redo the final 5 questions of PT1 based upon the restructure of the BB ACT");
    } else if (cellValue === "PTE1 - Combat Tactics") {
      Browser.msgBox('Course Information',"This training is optional but requires at least 5 officers to book it. This is a practical course. This training may take up to 1 hour.");
    } else if (cellValue === "PT1 - Induction Training - Review") {
      Browser.msgBox('Course Information',"This course is for people who have been instructed to redo the final 5 questions of PT1 based upon the restructure of the BB ACT");
  } 


      else if (cellValue === undefined) {  }
    else {
      Browser.msgBox('You have entered an invalid data, please select correct data corresponding to the Column.');   //This is in case they put a wrong course name
    }
  }
}
}

To sum up what the code currently does, when a user submits the input from a data validation, it will run through the if statement and finds that specific value and displays a browser message box specific to that value.

If no value is in the if range, it goes to else if which displays a message saying invalid data.

What I'm stuck on is creating custom buttons which are not "YES_NO" as described here

Next, I'm stuck on how to make a button take you to an external link when pressed by a user.

For example, the buttons I would like is, "Ok" and, "Go to the guide". Ok just shuts down the message box whilst the guide button takes you to the guide.

1

1 Answers

0
votes

Have you looked into modals - they would allow you to serve your own HTML, which would include custom buttons.

Documentation below - first is about Modal Dialogs, the second is the documentation on custom dialogs. They have simple examples which would get you started.

1) https://developers.google.com/apps-script/reference/base/ui#showModalDialog(Object,String)

2) https://developers.google.com/apps-script/guides/dialogs#custom_dialogs

Unrelated, but you may want to think about a switch statement - that's quite a chunk of else if's you have going.