Dynamic Text Boxes in Dialogue Window in Google Apps Script
up vote
1
down vote
favorite
I'm new to apps script and javascript so this may be a really basic question but I can't seem to find an answer to this issue anywhere.
I would like to have a dynamic dialogue box based on cell values in a certain field.
Here's my code so far.
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Stop Time Generator');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = targetSh.getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
if(values[i]!=""){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange(i+2,10).setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a number value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
}
I'm trying to have the dialog box pop up asking for the weight of the value in cell I2 first, then once submitted, the weight of the value in I3 etc.
So far it just pops up on a loop with a 0 above the text field
Any help would be greatly appreciated.
If there's a similar problem that I haven't found, please link me to it.
Thanks,
google-apps-script google-sheets dialog
add a comment |
up vote
1
down vote
favorite
I'm new to apps script and javascript so this may be a really basic question but I can't seem to find an answer to this issue anywhere.
I would like to have a dynamic dialogue box based on cell values in a certain field.
Here's my code so far.
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Stop Time Generator');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = targetSh.getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
if(values[i]!=""){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange(i+2,10).setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a number value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
}
I'm trying to have the dialog box pop up asking for the weight of the value in cell I2 first, then once submitted, the weight of the value in I3 etc.
So far it just pops up on a loop with a 0 above the text field
Any help would be greatly appreciated.
If there's a similar problem that I haven't found, please link me to it.
Thanks,
google-apps-script google-sheets dialog
Change:'Please Log waste weight for'&values[i],
to:'Please Log waste weight for: ' + values[i],
The plus sign must be used to concatenate text.
– Sandy Good
Nov 8 at 16:23
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm new to apps script and javascript so this may be a really basic question but I can't seem to find an answer to this issue anywhere.
I would like to have a dynamic dialogue box based on cell values in a certain field.
Here's my code so far.
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Stop Time Generator');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = targetSh.getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
if(values[i]!=""){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange(i+2,10).setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a number value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
}
I'm trying to have the dialog box pop up asking for the weight of the value in cell I2 first, then once submitted, the weight of the value in I3 etc.
So far it just pops up on a loop with a 0 above the text field
Any help would be greatly appreciated.
If there's a similar problem that I haven't found, please link me to it.
Thanks,
google-apps-script google-sheets dialog
I'm new to apps script and javascript so this may be a really basic question but I can't seem to find an answer to this issue anywhere.
I would like to have a dynamic dialogue box based on cell values in a certain field.
Here's my code so far.
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Stop Time Generator');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = targetSh.getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
if(values[i]!=""){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange(i+2,10).setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a number value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
}
I'm trying to have the dialog box pop up asking for the weight of the value in cell I2 first, then once submitted, the weight of the value in I3 etc.
So far it just pops up on a loop with a 0 above the text field
Any help would be greatly appreciated.
If there's a similar problem that I haven't found, please link me to it.
Thanks,
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Stop Time Generator');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = targetSh.getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
if(values[i]!=""){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange(i+2,10).setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a number value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
}
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Stop Time Generator');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = targetSh.getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
if(values[i]!=""){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange(i+2,10).setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a number value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
}
google-apps-script google-sheets dialog
google-apps-script google-sheets dialog
edited Nov 8 at 17:46
asked Nov 8 at 15:35
Jonathan Davis
83
83
Change:'Please Log waste weight for'&values[i],
to:'Please Log waste weight for: ' + values[i],
The plus sign must be used to concatenate text.
– Sandy Good
Nov 8 at 16:23
add a comment |
Change:'Please Log waste weight for'&values[i],
to:'Please Log waste weight for: ' + values[i],
The plus sign must be used to concatenate text.
– Sandy Good
Nov 8 at 16:23
Change:
'Please Log waste weight for'&values[i],
to: 'Please Log waste weight for: ' + values[i],
The plus sign must be used to concatenate text.– Sandy Good
Nov 8 at 16:23
Change:
'Please Log waste weight for'&values[i],
to: 'Please Log waste weight for: ' + values[i],
The plus sign must be used to concatenate text.– Sandy Good
Nov 8 at 16:23
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Try this code.
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Sheet3');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = ss.getSheetByName('Stop Time Generator').getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange('Q1').setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
This works except it also loops through values that are blank in the range I2:I
– Jonathan Davis
Nov 8 at 17:17
I added an if statement to filter those blanks out. Thanks!
– Jonathan Davis
Nov 8 at 17:46
Thanks for the feedback.
– Sandy Good
Nov 8 at 22:53
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Try this code.
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Sheet3');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = ss.getSheetByName('Stop Time Generator').getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange('Q1').setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
This works except it also loops through values that are blank in the range I2:I
– Jonathan Davis
Nov 8 at 17:17
I added an if statement to filter those blanks out. Thanks!
– Jonathan Davis
Nov 8 at 17:46
Thanks for the feedback.
– Sandy Good
Nov 8 at 22:53
add a comment |
up vote
0
down vote
accepted
Try this code.
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Sheet3');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = ss.getSheetByName('Stop Time Generator').getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange('Q1').setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
This works except it also loops through values that are blank in the range I2:I
– Jonathan Davis
Nov 8 at 17:17
I added an if statement to filter those blanks out. Thanks!
– Jonathan Davis
Nov 8 at 17:46
Thanks for the feedback.
– Sandy Good
Nov 8 at 22:53
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Try this code.
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Sheet3');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = ss.getSheetByName('Stop Time Generator').getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange('Q1').setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
Try this code.
function showPrompt() {
var L,sourceSheet,ss,targetSh;
ss = SpreadsheetApp.getActiveSpreadsheet();
targetSh = ss.getSheetByName('Sheet3');
sourceSheet = ss.getSheetByName('My Shift Log');
var ui = SpreadsheetApp.getUi(); // Same variations.
var values = ss.getSheetByName('Stop Time Generator').getRange('I2:I').getValues()
L = values.length;
for (var i = 0; i < L; i++){
var result = ui.prompt(
'Please Log waste weight for: ' + values[i],
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
Logger.log('text: ' + text)
if (button == ui.Button.OK) {
targetSh.getRange('Q1').setValue(text)
sourceSheet.getRange('d10').copyTo(targetSh.getRange('T1') , {contentsOnly:true});
if (!text) {
ui.alert('Please enter a value or click CANCEL');
}
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('Your response wasn't recorded');
break;
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('Your response wasn't recorded');
}
}
}
answered Nov 8 at 16:39
Sandy Good
20k105292
20k105292
This works except it also loops through values that are blank in the range I2:I
– Jonathan Davis
Nov 8 at 17:17
I added an if statement to filter those blanks out. Thanks!
– Jonathan Davis
Nov 8 at 17:46
Thanks for the feedback.
– Sandy Good
Nov 8 at 22:53
add a comment |
This works except it also loops through values that are blank in the range I2:I
– Jonathan Davis
Nov 8 at 17:17
I added an if statement to filter those blanks out. Thanks!
– Jonathan Davis
Nov 8 at 17:46
Thanks for the feedback.
– Sandy Good
Nov 8 at 22:53
This works except it also loops through values that are blank in the range I2:I
– Jonathan Davis
Nov 8 at 17:17
This works except it also loops through values that are blank in the range I2:I
– Jonathan Davis
Nov 8 at 17:17
I added an if statement to filter those blanks out. Thanks!
– Jonathan Davis
Nov 8 at 17:46
I added an if statement to filter those blanks out. Thanks!
– Jonathan Davis
Nov 8 at 17:46
Thanks for the feedback.
– Sandy Good
Nov 8 at 22:53
Thanks for the feedback.
– Sandy Good
Nov 8 at 22:53
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211075%2fdynamic-text-boxes-in-dialogue-window-in-google-apps-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Change:
'Please Log waste weight for'&values[i],
to:'Please Log waste weight for: ' + values[i],
The plus sign must be used to concatenate text.– Sandy Good
Nov 8 at 16:23