I want to create a prompt walk through of entering text into specific columns of google sheet (i.e. a set of Mandatory fields)
Firstly I'm very inexperienced in coding, so my attempt so far has is based on my research online. I'm sure I have over complicated the script by repeating elements of the script.
I want it to be able to do the following
1 - Click on custom menu. 2 - Click on Add new Risk. 3 - Prompt box asks 4 sequence of questions - (As an example Name, Age, Address & Job). 4 - The responses are captured and put into the next available row in the sheet. 5 - The prompt box cancels the whole process by clicking the cross or the cancel button.
Problems to overcome
1 - So far I can get the script to ask the sequence of questions however it only pastes the last question response the next available row.
2 - I cant work out how to cancel the process, it just brings up a message and carries on the sequence of commands
3 - I need my responses to be fixed to specific columns i.e - Not all pasted into A2,B2,C2,D2. For example Name(A2), Age (G2), Address (H2) , Job (X2)
Any help would be much appreciated
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.createMenu('Risk Menu')
.addItem('Add New Risk', 'showPrompt')
.addToUi();
}
function showPrompt() {
var ui = SpreadsheetApp.getUi(); // Same variations.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var targetSheet = ss.getSheetByName("Sheet1");
var range = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
var result = ui.prompt(
'Add New Risk - Madantory Field 1/4',
'Please enter your name:',
ui.ButtonSet.OK_CANCEL);
var button = result.getSelectedButton();
var text = result.getResponseText();
if (button == ui.Button.OK) {
// User clicked "OK".
range.setValue(text);
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('New risk cancelled');
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('You closed the dialog.');
}
var result2 = ui.prompt(
'Add New Risk - Mandatory Field 2/4',
'Please enter your address:',
ui.ButtonSet.OK_CANCEL);
var button2 = result2.getSelectedButton();
var text2 = result2.getResponseText();
if (button2 == ui.Button.OK) {
// User clicked "OK".
range.setValue(text2);
} else if (button2 == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('New risk cancelled');
} else if (button2 == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('You closed the dialog.');
}
var result3 = ui.prompt(
'Add New Risk - Mandatory Field 3/4',
'Please enter your age:',
ui.ButtonSet.OK_CANCEL);
var button3 = result3.getSelectedButton();
var text3 = result3.getResponseText();
if (button3 == ui.Button.OK) {
// User clicked "OK".
range.setValue(text3);
} else if (button3 == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('New risk cancelled');
} else if (button3 == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('You closed the dialog.');
}
var result4 = ui.prompt(
'Add New Risk - Mandatory Field 4/4',
'Please enter your job role:',
ui.ButtonSet.OK_CANCEL);
var button4 = result4.getSelectedButton();
var text4 = result4.getResponseText();
if (button4 == ui.Button.OK) {
// User clicked "OK".
range.setValue(text4);
} else if (button4 == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('New risk cancelled.');
} else if (button4 == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('You closed the dialog.');
}
}