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,










share|improve this question
























  • 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















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,










share|improve this question
























  • 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













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,










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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');
}
}
}





share|improve this answer





















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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');
}
}
}





share|improve this answer





















  • 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















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');
}
}
}





share|improve this answer





















  • 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













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');
}
}
}





share|improve this answer












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');
}
}
}






share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)