Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

javascript - 尝试将工作表行数据发送到GmailApp时缺少变量名; Javascript / Google App脚本(Missing variable name while trying to send sheet row data to GmailApp; Javascript/Google App script)

Still on a learning curve here.(这里仍然处于学习曲线上。)

I am trying to get data from a google sheet and send the data Gmail app but getting Missing variable name error.(我正在尝试从Google工作表中获取数据并发送数据Gmail应用程序,但出现缺少变量名错误。) This is what I have tried for the last 2 hours and I will appreciate help in structuring the code to work.(这是我过去2个小时内一直在尝试的工作,我将感谢您为代码的正常工作提供帮助。) function emailTheLastRow(){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getActiveSheet(); var range = sheet.getRange("AO2:AO"+sheet.getLastRow()).getValues(); var searchString = "1"; for (var i = 0; i<range.length; i++) { if(range[i][0] == searchString) { var lastRow = sheet.getRange(2+i,1,1,41).getValues(); var data = { 'email':lastRow[0][1], 'project':lastRow[0][2], 'client':lastRow[0][3], 'sdate':lastRow[0][4], 'edate':lastRow[0][5], 'loe':lastRow[0][7], }; GmailApp.sendEmail("[email protected]", "Project", "A new project has been created with the following details: " + data()); } } }   ask by levi translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're trying to concatenate a string with a JSON, which is an object and not a string.(您正在尝试使用JSON连接字符串,JSON是一个对象而不是字符串。)

Use stringify function [1] to convert the object to a string.(使用stringify函数[1]将对象转换为字符串。) Add this line after you declare data variable:(声明data变量后添加以下行:) data = JSON.stringify(data); [1] https://www.w3schools.com/js/js_json_stringify.asp([1] https://www.w3schools.com/js/js_json_stringify.asp)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...