TypeError: Cannot read property 'getResponse' of undefined - google-forms

I am trying to write a script, that automatically sends an email when the form is submitted. This is the code I wrote:
function autoEmail(e) {
var response = e.response;
var formResponses = response.getItemResponses();
var email = formResponses[1].getResponse();
var name = formResponses[2].getResponse();
var size = formResponses[3].getResponse();
var subject = "Confirmation";
var body = "Dear " + name + " your size is " + size;
MailApp.sendEmail(email, subject, body)
}
When I try to run this simple code, I get: TypeError: Cannot read property 'getResponse' of undefined

Related

Sending data with email

I have a google-app-maker, and it show some row data table. Every time it's row clicked, it will go to a page. And on that page there is button for sending invoice information. So recipient is static.
Client Name : Name_of_Client
But I can not grab field Name_of_Client into Msg
OnClick Script :
/* var widgets = widget.parent.descendants; */
var to = "webmaster#domain.com";
var subject = "Invoice Report";
var msg = "Client Name widget.datasource.item.Client_Name";
/* widgets.EmailStatus.text = 'Sending email...'; */
SendEmail(to, subject, msg);
Client Script :
function clearEmailForm(){
}
function SendEmail(To, Subject, Msg){
var status = "sending";
google.script.run.withSuccessHandler(function(result) {
status.text = 'Email sent...';
clearEmailForm();
})
.SendEmail(To, Subject, Msg);
}
Server Script :
function SendEmail(to, subject, msg){
MailApp.sendEmail(to, subject , msg);
}
The widget reference should be outside the string:
var msg = "Client Name " + widget.datasource.item.Client_Name;
Sometimes widgets don't inherit the datasource as expected, so you may need to reference the page or page fragment by using parent or root.
var msg = "Client Name " + widget.root.datasource.item.Client_Name;

Parsing error while sending data from google spreads to Firebase

I am sending data from my google spreadsheet to Firebase. My data contains values such as "0.5 ml", "2.5 ml", etc. App Script is not being able to parse this data. Here is my code
function myFunction() {
var ss = SpreadsheetApp.openById("****");
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
var dataToImport = {};
for(var i = 1; i < data.length; i++) {
var Name = data[i][1];
dataToImport[Name] = {
Name: Name,
};
}
var secret ="*****"
var firebaseUrl = "******";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl,secret);
base.setData("", dataToImport);
}
This is the error that I am getting:
"Error: 400 - Invalid data; couldn't parse key beginning at 1:2. Key value can't be empty or contain $ # [ ] / or . (line 303, file "Code", project "FirebaseApp")"
The reason behind the error is the fact that Firebase does not allow some special characters in the Key of the child. As one can see my original code, I was using the name itself as my key, which contains characters like "."
I have changed my code as follows so that the key is set randomly and it is working fine:
function myFunction() {
var ss = SpreadsheetApp.openById("*****");
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
var dataToImport = {};
var secret ="*****"
var firebaseUrl = "*****";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl,secret);
for(var i = 1; i < data.length; i++) {
dataToImport = {
Name:data[i][1]
};
Logger.log(base.pushData("*****", dataToImport));
}
}

CosmosDB Stored Procedure returns error "Encountered exception while executing Javascript. Exception = Error: Invalid arguments for query"

I have below stored procedure which is written to work on continuation token based mechanism for fetching documents from the documentDB collection:
I am getting exception with query.
I am trying to get all the documents using continuation token.
Is this the correct way?
function getOrdersByBranchNumber(branchNumber){
var context = getContext();
var collection = context.getCollection();
var link = collection.getSelfLink();
var response = context.getResponse();
var nodesBatch = [];
var continuationToken = true;
var responseSize = 0;
//validate inputs
if(!branchNumber || (typeof branchNumber != "string")){
return errorResponse(400, (!branchNumber) ? "branchNumber is Undefined":"String type is expected for branchNumber.");
}
var querySelect = "SELECT * from orders o WHERE o.branchNbr = '"+branchNumber+"' ";
var query = { query: querySelect};
getNodes(continuationToken);
function getNodes(continuationToken) {
var requestOptions = {
continuation: continuationToken,
pageSize: 90
};
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
query,
requestOptions,
function (err, feed, options) {
var queryPageSize = JSON.stringify(feed).length;
// DocumentDB has a response size limit of 1 MB.
if (responseSize + queryPageSize < 1024 * 1024) {
// Append query results to nodesBatch.
nodesBatch = nodesBatch.concat(feed);
// Keep track of the response size.
responseSize += queryPageSize;
if (responseOptions.continuation) {
// If there is a continuation token... Run the query again to get the next page of results
lastContinuationToken = responseOptions.continuation;
getNodes(responseOptions.continuation);
} else {
// If there is no continutation token, we are done. Return the response.
var feedData=JSON.stringify(nodesBatch);
getContext().getResponse().setBody(feedData);
}
} else {
// If the response size limit reached; run the script again with the lastContinuationToken as a script parameter.
var feedData=JSON.stringify(nodesBatch);
getContext().getResponse().setBody(feedData);
}
});
if (!isAccepted){
return errorResponse(400, "The query was not accepted by the server.");
}
}
function errorResponse(code,message){
var errorObj = {};
errorObj.code = code;
errorObj.message = message;
errorObj.date = getDateTime();
return response.setBody(errorObj);
}
function getDateTime(){
var currentdate = new Date();
var dateTime = currentdate.getFullYear() + "-" +(currentdate.getMonth()+1)+ "-" + currentdate.getDate()+ " " +currentdate.getHours()+":"+currentdate.getMinutes() +":"+currentdate.getSeconds();
return dateTime;
}
}
But I am seeing below mentioned error after saving and executing the stored procedure.
Any idea as to what is wrong in query?
Encountered exception while executing Javascript. Exception = Error: Invalid
arguments for query.
Stack trace: Error: Invalid arguments for query.
at queryDocuments (getOrdersByBranchNumber.js:614:17)
at getNodes (getOrdersByBranchNumber.js:27:5)
at getOrdersByBranchNumber (getOrdersByBranchNumber.js:19:1)
at __docDbMain (getOrdersByBranchNumber.js:78:5)
at Global code (getOrdersByBranchNumber.js:1:2)
Try removing the continuation item on the query options. I got this error when I had an invalid one specified.

Sending parameter along URL actionscript

As part of a mobile app I'm building I have to authenticate trough the API of Last.FM.
As documented on their website I tried to format to url correctly but appearently I'm doing something wrong because I get error:
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession
Last.FM documentation: http://www.last.fm/api/mobileauth
My code below:
var username:String = "xxxxxxx";
var password:String = "xxxxxxxxxxxx";
var api_key:String = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
var secret:String = "xxxxxxxxxxxxxxxxxxxxxx";
var api_sig:String = MD5.hash( "api_key" + api_key + "methodauth.getMobileSessionpassword" + password + "username" + secret);
var request:URLRequest = new URLRequest("https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession");
var variables:URLVariables = new URLVariables();//create a variable container
variables.username =username;
variables.password = password;
variables.api_key = api_key;
variables.api_sig = api_sig;
request.data = variables;
request.method = URLRequestMethod.POST;//select the method as post/
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.load(request);//send the request with URLLoader()
Does someone know the answer?
Try to use HTTPService instead of URLLoader. Smth like this:
var http:HTTPService = new HTTPService();
http.useProxy = false;
http.resultFormat = "e4x";
http.method = "POST";
http.url = "https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession";
var variables:Object = {};
variables.username = username;
variables.password = password;
variables.api_key = api_key;
variables.api_sig = api_sig;
var token:AsyncToken = http.send(variables);
var responder:Responder = new Responder(handleRequestComplete, handleError);
token.addResponder(responder);
Where handleRequestComplete and handleError are your handlers for the request results:
private function handleRequestComplete(event:ResultEvent):void
{
// your code here
}
private function handleError(event:FaultEvent):void
{
// your code here
}

Flex: Getting feedback from URLLoader after sending information to a coldfusion file

I have a scheduling application that allows users to save any changes. When the user clicks the save button, Flex sends all the information to a coldfusion script which picks the information apart and sends saves it to the database. That all works well and good, but I would like to be able to display some sort of text to the user saying something like "Your file was successfully saved" or "There has been an error. Please contact the administrator".
My AS function is as follows:
import flash.net.URLLoader;
import flash.net.URLRequest;
private function save():void
{
var tempString:String = new String;
// Set up a URL request, loader, and variables
var progressOutURL:URLRequest = new URLRequest("saveSchedule.cfm");
var progressOutLoader:URLLoader = new URLLoader();
var progressOutVars:URLVariables = new URLVariables(); // Set the variables to be sent out
for (var i:int = 0; i < wholeProject.length; i++)
{
tempString = new String;
tempString = wholeProject[i].projectTitle + "|" + wholeProject[i].workingTitle + "|" + wholeProject[i].startDate + "|";
for (var j:int = 0; j < wholeProject[i].thisBlock.length; j++)
{
tempString = tempString + wholeProject[i].thisBlock[j].startOffset + "," + wholeProject[i].thisBlock[j].numDays + "," + wholeProject[i].thisBlock[j].role + "," + wholeProject[i].thisBlock[j].sID + "," + wholeProject[i].thisBlock[j].isConflict + "," + wholeProject[i].thisBlock[j].positionType + ";";
}
progressOutVars["project" + i] = tempString;
}
progressOutURL.method = URLRequestMethod.POST;
progressOutURL.data = progressOutVars;
progressOutLoader.load (progressOutURL);
}
And my coldfusion file is as follows (right now it just saves a cfdump of the information so that I can be sure the data was sent):
<cfsavecontent variable="toOutput">
<cfdump var="#FORM#" />
</cfsavecontent>
<cffile action="write" file="#GetDirectoryFromPath(GetCurrentTemplatePath())#output.html" output="#toOutput#" />
Is there any way that the "progressOutLoader.load(progressOutURL);" returns a boolean or something saying whether or not the send was successful?
progressOutLoader.addEventListener(Event.COMPLETE,resultHandler);
public function resultHandler(event:Event):void {
Alert.show("Success");
}
Similarly handle other events too.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html
Why are you not using Flex HTTPService? instead of URLLoader

Resources