[英]How to create a popup using Google Apps Script only if a certain button is pushed on the previous popup and remove text box?
我下面的代码打开 4 个文本框,1 个询问是/否问题,3 个询问确定/取消问题。 他们每个人都接受文本,但我希望第一个问题只接受没有文本框的按钮 YES 和 NO。 此外,如果第一个问题的答案是否定的,我希望它跳过第二个问题和 go 直接到第三个问题。
问题如下:
function TextBox() {
var ui = SpreadsheetApp.getUi();
const sheet = SpreadsheetApp.openById('1JZ-v5n5m0_lyaoLgsHDAa78AtYNP5AsUDo2NRpJbwG4').getSheetByName('HOT & WARM CLIENTS');
sheet.sort(9)
var today = Utilities.formatDate(new Date(), "GMT-6", "MM/dd/yy")
var ui = SpreadsheetApp.getUi();
var valuesToCopy = sheet.getRange("C5:J5").getDisplayValues().map(r => r.join(' \n '));
var ar2 = [
{
message: valuesToCopy + "\n\n Did we do work for this client today/yesterday? (YES/NO)",
range: "G5"
}
];
var ar3 = [
{ // promptUPDATE3
message: valuesToCopy + "\n\n What did we help this client with today?",
range: "H5"
},
];
var ar = [
// { // promptUPDATE3
// message: valuesToCopy + "\n\n What did we help this client with today?",
// range: "PREVIOUS"
// },
{ // promptUPDATE
message: valuesToCopy + "\n\n When should we follow up with this client next? (MM/DD/YY)",
range: "I5"
},
{ // promptUPDATE2
message: valuesToCopy + "\n\n Next Follow Up Activity?",
range: "J5"
}
];
ar2.forEach(({message, range }) => {
var res = ui.prompt(message, ui.ButtonSet.YES_NO);
if (res.getSelectedButton() == ui.Button.YES) {
sheet.getRange("G5").setValue(today);
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
})
ar3.forEach(({ message, range }) => {
var res = ui.prompt(message, ui.ButtonSet.OK_CANCEL);
var lastRowSourceData = sheet.getRange("H5").getValue();
var lastActivity = SpreadsheetApp.openById('1JZ-v5n5m0_lyaoLgsHDAa78AtYNP5AsUDo2NRpJbwG4').getSheetByName('HOT & WARM CLIENTS').getRange("H5").getValue();
if (res.getSelectedButton() == ui.Button.OK) {
sheet.getRange(range).setValue(lastActivity+" | "+res.getResponseText());
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
})
ar.forEach(({ message, range }) => {
var res = ui.prompt(message, ui.ButtonSet.OK_CANCEL);
if (res.getSelectedButton() == ui.Button.OK) {
sheet.getRange(range).setValue(res.getResponseText());
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
})
}
也许您可以尝试下面这个经过调整的脚本。 这将对第一个问题使用alert
Class Ui 方法,如果用户选择NO
,则使用if condition
跳过问题的顺序。
据我了解,这是您要实现的流程:
Textbox
,而应仅向用户提供 select YES
或NO
按钮。NO
,则将用户转到第三个问题。注意:此示例脚本将仅处理工作表中的第一个客户端,就像在实际脚本中一样。 如果我误解了什么或者还有什么遗漏,请随时告诉我。
function TextBox() {
var ui = SpreadsheetApp.getUi();
var today = Utilities.formatDate(new Date(), "GMT-6", "MM/dd/yy");
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('HOT & WARM CLIENTS');
sheet.sort(9);
var sheetData = sheet.getRange("C5:J5").getDisplayValues();
var questions = [['\n\n Did we do work for this client today/yesterday? (YES/NO)', "G"],
['\n\n What did we help this client with today?', "H"],
['\n\n When should we follow up with this client next? (MM/DD/YY)', "I"],
['\n\n Next Follow Up Activity?', "J"]];
var row = "5"; //ONLY process current client on 5th row
var clientDetails = sheetData[0].join('\n');
/**First question */
var q1 = ui.alert(clientDetails + questions[0][0], ui.ButtonSet.YES_NO)
if (q1 == ui.Button.YES) {
sheet.getRange(questions[0][1] + row).setValue(today);
/**End of the First question */
/**Second question */
var q2 = ui.prompt(clientDetails + questions[1][0], ui.ButtonSet.OK_CANCEL);
var lastActivity = sheet.getRange(questions[1][1] + row).getValue();
q2.getSelectedButton() == ui.Button.OK ? sheet.getRange(questions[1][1] + row).setValue(lastActivity + " | " + q2.getResponseText()) : console.log('The user clicked "No" or the dialog\'s close button.');
/**End of the Second question*/
/**Third question */
var q3 = ui.prompt(clientDetails + questions[2][0], ui.ButtonSet.OK_CANCEL);
q3.getSelectedButton() == ui.Button.OK ? sheet.getRange(questions[2][1] + row).setValue(q3.getResponseText()) : console.log('The user clicked "No" or the dialog\'s close button.');
/**End of the Third question*/
/**Fourth question */
var q4 = ui.prompt(clientDetails + questions[3][0], ui.ButtonSet.OK_CANCEL);
q4.getSelectedButton() == ui.Button.OK ? sheet.getRange(questions[3][1] + row).setValue(q4.getResponseText()) : console.log('The user clicked "No" or the dialog\'s close button.');
/**End of the Fourth question*/
} else {
/**Skip to the third question if 'NO' was selected on the first question*/
var q3 = ui.prompt(clientDetails + questions[2][0], ui.ButtonSet.OK_CANCEL);
q3.getSelectedButton() == ui.Button.OK ? sheet.getRange(questions[2][1] + row).setValue(q3.getResponseText()) : console.log('The user clicked "No" or the dialog\'s close button.');
/**End to fourth question*/
var q4 = ui.prompt(clientDetails + questions[3][0], ui.ButtonSet.OK_CANCEL);
q4.getSelectedButton() == ui.Button.OK ? sheet.getRange(questions[3][1] + row).setValue(q4.getResponseText()) : console.log('The user clicked "No" or the dialog\'s close button.');
}
}
- 快速测试
- 例如,如果用户在第first question
上选择NO
,然后跳到third question
我不认为在你的对象中添加评论是个好主意
试试这样:
function lfunko() {
var ui = SpreadsheetApp.getUi();
const sheet = SpreadsheetApp.openById('1JZ-v5n5m0_lyaoLgsHDAa78AtYNP5AsUDo2NRpJbwG4').getSheetByName('HOT & WARM CLIENTS');
sheet.sort(9)
var today = Utilities.formatDate(new Date(), "GMT-6", "MM/dd/yy")
var ui = SpreadsheetApp.getUi();
var valuesToCopy = sheet.getRange("C5:J5").getDisplayValues().flat().map(r => r.join(' \n '));
var ar2 = [{ message: valuesToCopy + "\n\n Did we do work for this client today/yesterday? (YES/NO)", range: "G5" }];
var ar3 = [{ message: valuesToCopy + "\n\n What did we help this client with today?", range: "H5" }];
var ar = [{ message: valuesToCopy + "\n\n What did we help this client with today?", range: "PREVIOUS" }, { message: valuesToCopy + "\n\n When should we follow up with this client next? (MM/DD/YY)", range: "I5" }, { message: valuesToCopy + "\n\n Next Follow Up Activity?", range: "J5" }];
ar2.forEach(obj => {
var res = ui.prompt(obj.message, ui.ButtonSet.YES_NO);
if (res.getSelectedButton() == ui.Button.YES) {
sheet.getRange("G5").setValue(today);
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
});
ar3.forEach(obj => {
var res = ui.prompt(obj.message, ui.ButtonSet.OK_CANCEL);
var lastRowSourceData = sheet.getRange("H5").getValue();
var lastActivity = SpreadsheetApp.openById('1JZ-v5n5m0_lyaoLgsHDAa78AtYNP5AsUDo2NRpJbwG4').getSheetByName('HOT & WARM CLIENTS').getRange("H5").getValue();
if (res.getSelectedButton() == ui.Button.OK) {
sheet.getRange(range).setValue(lastActivity + " | " + res.getResponseText());
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
});
ar.forEach((obj) => {
var res = ui.prompt(obj.message, ui.ButtonSet.OK_CANCEL);
if (res.getSelectedButton() == ui.Button.OK) {
sheet.getRange(obj.range).setValue(res.getResponseText());
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
});
}
并且 UI 不包含任何下拉选项。 您必须使用 html 构建一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.