首页 > 解决方案 > Apple 中的 dopost(e) 功能问题

问题描述

试图写一个谷歌表格并开发一个应用程序来从表格中获取数据,发送短信,并在发送消息后,更新表格上的一个字段(发送短信)

The goGet function seems to work, the doPost function chokes. 

const doPost = (e) => {
    const sheet = SpreadsheetApp.openByUrl(SHEET_URL).getSheetByName(SHEET_NAME);
    const [header] = sheet.getRange('A1:1').getValues();
    const Status1 = header.indexOf('Status1');
    var rowId = Number(e.parameter.row);
    sheet.getRange(rowId + 1, STATUS1 + 1).setValue('SMS Sent');
    return ContentService.createTextOutput('').setMimeType(
        ContentService.MimeType.TEXT
    );
}; 

我最初使用以下教程进行设置:https ://www.labnol.org/send-sms-google-sheets-200402

我做了一些修改。所以我无论如何都无法让上述函数工作,当我尝试它时它说“TypeError:无法读取未定义的doPost的属性'参数'”它是教程中的确切代码,只是状态更改为状态1。使用教程我已经更新了我的工作表网址和名称。

所以第二部分是我有复选框。我有使用复选框的 doGet 函数,并且只向前面有复选框的消息发送文本(如果 SMS1 为 True,则推送 Row[Phone],row[text1])。但是我需要 doPost 函数来更新与哪个复选框为真相关的统计字段(如果 SMS1 为真,则使用“SMS Sent”更新 Status1)等等。

完整代码如下:

// Enter your Twilio account information here
var TWILIO_ACCOUNT_SSID = 
var TWILIO_SMS_NUMBER = 
var TWILIO_AUTH_TOKEN = 

//https://script.google.com/macros/s?A...

const SHEET_URL = "https://docs.google.com/spreadsheets/d/1.../edit#gid=0";
const SHEET_NAME = "Alert";

const doGet = () => {
    const sheet = SpreadsheetApp.openByUrl(SHEET_URL).getSheetByName(SHEET_NAME);
    const [header, ...data] = sheet.getDataRange().getDisplayValues();

    const Phone = header.indexOf('Phone');
    const Text1 = header.indexOf('Text1');
    const Text2 = header.indexOf('Text2');
    const Text3 = header.indexOf('Text3');
    const Text4 = header.indexOf('Text4');
    const Text5 = header.indexOf('Text5');
    const Text6 = header.indexOf('Text6');
    const Text7 = header.indexOf('Text7');
    const Text8 = header.indexOf('Text8');
    const Text9 = header.indexOf('Text9');
    const Text10 = header.indexOf('Text10');
    const Text11 = header.indexOf('Text11');
    const Text12 = header.indexOf('Text12');
    const Text13 = header.indexOf('Text13');
    const Text14 = header.indexOf('Text14');
    const Text15 = header.indexOf('Text15');
    const Text16 = header.indexOf('Text16');
    const Text17 = header.indexOf('Text17');
    const Text18 = header.indexOf('Text18');
    const Status1 = header.indexOf('Status1');
    const Status2 = header.indexOf('Status2');
    const Status3 = header.indexOf('Status3');
    const Status4 = header.indexOf('Status4');
    const Status5 = header.indexOf('Status5');
    const Status6 = header.indexOf('Status6');
    const Status7 = header.indexOf('Status7');
    const Status8 = header.indexOf('Status8');
    const Status9 = header.indexOf('Status9');
    const Status10 = header.indexOf('Status10');
    const Status11 = header.indexOf('Status11');
    const Status12 = header.indexOf('Status12');
    const Status13 = header.indexOf('Status13');
    const Status14 = header.indexOf('Status14');
    const Status15 = header.indexOf('Status15');
    const Status16 = header.indexOf('Status16');
    const Status17 = header.indexOf('Status17');
    const Status18 = header.indexOf('Status18');
    const SMS1 = header.indexOf('SMS1');
    const SMS2 = header.indexOf('SMS2');
    const SMS3 = header.indexOf('SMS3');
    const SMS4 = header.indexOf('SMS4');
    const SMS5 = header.indexOf('SMS5');
    const SMS6 = header.indexOf('SMS6');
    const SMS7 = header.indexOf('SMS7');
    const SMS8 = header.indexOf('SMS8');
    const SMS9 = header.indexOf('SMS9');
    const SMS10 = header.indexOf('SMS10');
    const SMS11 = header.indexOf('SMS11');
    const SMS12 = header.indexOf('SMS12');
    const SMS13 = header.indexOf('SMS13');
    const SMS14 = header.indexOf('SMS14');
    const SMS15 = header.indexOf('SMS15');
    const SMS16 = header.indexOf('SMS16');
    const SMS17 = header.indexOf('SMS17');
    const SMS18 = header.indexOf('SMS18');

    const output = [];

    data.forEach((row, index) => {
        if (row[SMS1] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text1]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS2] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text2]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS3] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text3]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS4] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text4]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS5] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text5]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS6] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text6]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS7] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text7]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS8] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text8]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS9] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text9]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS10] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text10]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS11] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text11]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS12] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text12]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS13] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text13]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS14] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text14]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS15] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text15]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS16] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text16]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS17] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text17]]);    
        }
    }) ;
    data.forEach((row, index) => {
        if (row[SMS18] === 'TRUE') {
            output.push([index + 1, row[Phone], row[Text18]]);    
        }
    }) ;
        
    const json = JSON.stringify(output);

    return ContentService.createTextOutput(json).setMimeType(ContentService.MimeType.TEXT);
}

const doPost = (e) => {
    const sheet = SpreadsheetApp.openByUrl(SHEET_URL).getSheetByName(SHEET_NAME);
    const [header] = sheet.getRange('A1:1').getValues();
    const Status1 = header.indexOf('Status1');
    var rowId = Number(e.parameter.row);
    sheet.getRange(rowId + 1, STATUS1 + 1).setValue('SMS Sent');
    return ContentService.createTextOutput('').setMimeType(
        ContentService.MimeType.TEXT
    );
};

    

标签: google-apps-script

解决方案


推荐阅读