簡體   English   中英

僅當在上一個彈出窗口上按下某個按鈕並刪除文本框時,如何使用 Google Apps 腳本創建彈出窗口?

[英]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 直接到第三個問題。

問題如下:

  • 我們今天/昨天為這個客戶工作了嗎? [是/否]
  • 我們今天為這位客戶提供了什么幫助? [文本框][確定/取消] ***如果之前的答案是否定的則跳過
  • 我們接下來應該什么時候跟進這個客戶? (MM/DD/YY) [文本框][確定/取消]
  • 下一個跟進活動? [文本框][確定/取消]
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跳過問題的順序。

據我了解,這是您要實現的流程:

  1. 一個問題不應有Textbox ,而應僅向用戶提供 select YESNO按鈕。
  2. 如果用戶在第一個問題上選擇NO ,則將用戶轉到第三個問題
  3. 否則,系統將按順序提示用戶問題。

注意:此示例腳本將僅處理工作表中的第一個客戶端,就像在實際腳本中一樣。 如果我誤解了什么或者還有什么遺漏,請隨時告訴我。

樣本調整腳本

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM