我下面的代碼打開 4 個文本框,1 個詢問是/否問題,3 個詢問確定/取消問題。他們每個人都接受文本,但我希望第一個問題只接受按鈕 YES 和 NO 沒有文本框。另外,如果第一個問題的答案是否定的,我希望它跳過第二個問題并直接進入第三個問題。
問題如下:
- 我們今天/昨天為這個客戶作業了嗎?[是/否]
- 我們今天為這位客戶提供了什么幫助?[文本框][OK/CANCEL] ***如果上一個答案為否,則跳過
- 接下來我們應該什么時候跟進這個客戶?(月/日/年)[文本框][確定/取消]
- 下一個跟進活動?[文本框][確定/取消]
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.');
}
})
}
uj5u.com熱心網友回復:
建議 [腳本更新]
也許你可以試試下面這個經過調整的腳本。如果用戶選擇 ,這將使用alertClass Ui 方法處理第一個問題和if condition跳過問題的順序NO。
據我了解,這是您想要實作的流程:
- 第一個問題不應該有一個
Textbox而只給用戶選擇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.');
}
}
示范
- 快速測驗

- 例如,如果用戶選擇NO&first question然后被跳到third question

參考
- 警報(提示,按鈕)
uj5u.com熱心網友回復:
我不認為在你的物件中添加評論是一個好主意
試試這種方式:
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 構建一個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/512411.html
下一篇:狀態更改不會觸發重新渲染
