I'm currently trying to create a custom UI dialogs with google app scripts.
Here's my current script:
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") {
}
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
}
}
}
}
Now, I have found that browser message boxes cannot support custom buttons but a UI can.
I'm trying to add this to the code for each if statement, however each one will be different.
Code:
// Display a dialog box with a message and "Ok" and "Guide" buttons. The user can also close the
// dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.alert("PT1 - Induction Training:\\n\\nType: Theory \\n\\nTime Needed: 15-20 Minutes\\n\\n Learning Resource/Manual: BBACT, Forum Post: Rules for Officers", ui.ButtonSet.OK_GUIDE);
// Process the user's response.
if (response == ui.Button.OK) {
Logger.log('The user clicked "Ok."');
} else {
Logger.log('The user clicked "Guide", open up guide link: www.britishborders.co.uk/laws');
}
Essentially, I want a custom dialog to appear when a particular value is inputted as seen in the IF statements. In that dialog box, it will show course information as well as the ability to close the box by selecting, "Ok" and also they can view the guide by clicking, "Guide".
Any help is appreciated.