I am trying to make a form in google app maker. I've created a form. which has a "preview(save" button, It will create a new item and I have a field named "status". The default value of this field is "draft". In the next page I have a "sent email" button. This page won't create any new item. It'll send the email and if the email deliver is successful then it'll update the field of status from "draft" to "completed"
This is my client script
function sendMessage(to, subject, msg){
// some part is omitted
var status = app.popups.NotificationDialog.descendants.notificationText;
var success = app.datasources.ChangeSystem;
google.script.run
.withFailureHandler(function(error){
// success.Success = "draft"
status.text = error.message;
})
.withSuccessHandler(function(result){
status.text = 'sent';
success.Success = "completed";
clearEmailForm();
})
.sendEmailMessage(to, subject, msg);
}
and this is my email sent button function
var widgets = app.pages.Email.descendants;
var to;
var subject = widgets.systemName.value
var msg = "Description:\n\t\t" + widgets.Objective.value;
widgets.EmailStatus.text = 'Sending email...';
sendMessage(to, subject, msg);
So far I am successful to send the email also I have created and saved all fields. But the problem is after sending the email the "status" field doesn't update. It remains the same as default value "draft". my expected result is after pressing the send button it will update one of the existing fields.
After some additional thinking on this topic I think I found the problem. Here is some updated code assuming your send email button is the same inherited datasource as the field that you are trying to update.
var success = widget.datasource.item;
google.script.run
.withFailureHandler(function(error)
status.text = error.message;
success.Success = 'draft';
})
.withSuccessHandler(function(result) {
status.text = 'Email sent';
success.Success = 'completed';
clearEmailForm();
})
.sendEmailMessage(to,subject, msg);
Related
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;
I have selected a user name from dropdown list values are from Directory, I would like to get that user's email address from the directory, I have tried in this way but it didn't work, could someone please help.
Image
`\\ client script
function getEmailAddress(Name)
{
var Email = EmailAddress(Name);
return Email;
}
\\Server Script
function EmailAddress(Name)
{
var query = app.models.Directory.newQuery();
query.filters.PrimaryEmail._contains.substring(Name);
return query.run();
}`
I got an solution for this, when I choose a person name from dropdown this gives person's email address automatically into email address field.
//Widget binding
setEmailAddress(#widget, #widget.root.descendants.EmployeeName.value)
//Client script
function setEmailAddress(widget, Fullname)
{
google.script.run
.withSuccessHandler(function(result){
widget.value = result;
})
.withFailureHandler(function(error){
error = "unable to load user's mail id";
console.error(error);
}) .getEmailAddress(Fullname);
}
}
//Server script
function getEmailAddress(Fullname){
var directoryQuery = app.models.Directory.newQuery();
directoryQuery.filters.FullName._equals = Fullname;
var person = directoryQuery.run()[0];
return person.PrimaryEmail;
}
i am developing my app on google calendar integration. I got the error "Object Not initialized" when i am adding attendee to the EventAttendee object. Please review the code below...
Event Entry = new Event();
Entry.Summary = MeetingName;
Entry.Description = MeetingDetails;
EventDateTime dt_Start = new EventDateTime();
dt_Start.DateTime = meeting.StartTime.ToString("yyyy-MM-ddThh:mm:ss.000Z");
Entry.Start = dt_Start;
EventDateTime dt_End = new EventDateTime();
dt_End.DateTime = meeting.EndTime.ToString("yyyy-MM-ddThh:mm:ss.000Z");
Entry.End = dt_End;
if (invitees != null)
{
foreach (Participant invitee in invitees)
{
String str = invitee.Email;
str = invitee.Name;
Entry.Attendees.Add(new EventAttendee()
{
Email = invitee.Email,
DisplayName = WEB.HttpUtility.HtmlDecode(invitee.Name),
ResponseStatus = "accepted",
Organizer=false,
Resource=false
});
}
}
place where i am doing "Entry.Attendees.Add(new EventAttendee()" at this point i am getting the error...
I think you need to instantiate the list of EventAttendees first.
Try adding this after you create the entry-
Entry.Attendees = new List<EventAttendee>();
Then you could try this to add them-
var att = new EventAttendee()
{
DisplayName = "Bill Smith",
Email = "emailsmith#smith.test",
Organizer = false,
Resource = false,
};
Entry.Attendees.Add(att);
You should not be setting anything other than the email address for the attendee. The response status is for the attendee to set (why would you be able to accept a meeting for me that you created?) and the Organizer and Resource attributes are set by Google. It may be possible to set a DisplayName but it is not mandatory.
I'm trying to create a Facebook Mobile Application using asp.net and MVC3 and integrate Facebook Credits as a payment method. First of all, taking the recent annoucements into consideration, is it now possible to have a mobile web application that accepts Facebook Credits?
If so, I've taken the example provided in the following post
http://www.m-webs.com/blog_facebookcredits.html
And implemented the following Controller action:
public JsonResult CallBack()
{
string fborder_info = Request.Form["order_info"];
string fborder_id = Request.Form["order_id"];
string fbmethod = Request.Form["method"];
if (fbmethod == "payments_get_items")
{
fborder_info = fborder_info.Substring(1, (fborder_info.Length - 2)); // remove the quotes
ulong credscost = 2; // Price of purchase in facebook credits
var theItem = new FacebookBuyItem()
{
item_id = 123456789,
description = "Own yours today!",
price = credscost,
title = "Digital Unicorn",
product_url = "http://www.facebook.com/images/gifts/21.png",
image_url = "http://www.facebook.com/images/gifts/21.png"
};
var res = new Dictionary<string, object>();
res["method"] = fbmethod;
res["order_id"] = fborder_id;
res["content"] = new object[] { theItem };
var jss = new JavaScriptSerializer();
var ob = jss.Serialize(res);
ob = ob.Replace("#$", #"\/".Replace("//", #"\/"));
return Json(ob, JsonRequestBehavior.AllowGet);
}
return null;
}
I've verified that the callback is being requested by facebook, and I've also captured the response being sent back, which appears to contain all of the required information to display the purchase dialog, but I'm still getting the following error message:
API Error Code: 1151
API Error Description: Sorry, but this app may not be eligible to accept Facebook Credits. If this app has accepted credits before, please try again.
Error Message: Invalid Application
and when tested from a mobile browser:
Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again.
I've also noticed that my callback is being requested twice which doesn't seem right either.
Any insight into how to get my integration up and running would be greatly appreciated. My Facebook AppId is 177876855621874
Thanks.
Update: So I played around with the examples given and reverted back to webforms in order to test the example given at http://www.m-webs.com/blog_facebookcredits.html. In order to get this solution working in an asp.net MVC3 application I had to change the action type to HttpResponse instead of JsonResult which makes sense as the JsonResult leaves elements out that would normally be included in a HttpResponse.
So the Controller Action ended up looking like this:
[HttpPost]
public HttpResponse CallBack()
{
if (Request.Form["signed_request"] != null)
{
var decodeFbSignedRequest = FacebookSignedRequest.Parse(FacebookApplication.Current.AppSecret,
Request.Form["signed_request"]);
LogHelper.MicroLogMsg("SIGNED REQUEST DECODE:: " + decodeFbSignedRequest.Data);
}
string fborder_id = Request.Form["order_id"];
string fbmethod = Request.Form["method"];
string fborder_info = Request.Form["order_info"]; // Use this to look up a product on the database..
if (fbmethod == "payments_get_items")
{
int credscost = 2; // Price of purchase in facebook credits
var theItem = new FacebookBuyItem()
{
item_id = "123456AA",
description = "[Test Mode] Own yours today!",
price = credscost,
title = "[Test Mode] Digital Unicorn",
product_url = #"http:\/\/www.facebook.com\/images\/gifts\/21.png",
image_url = #"http:\/\/www.facebook.com\/images\/gifts\/21.png"
};
// Return the initial response to FB
//------------------------------------------
var res = new Dictionary<string, object>();
res["method"] = fbmethod;
res["content"] = new object[] { theItem };
var jss = new JavaScriptSerializer();
string ob = jss.Serialize(res);
LogHelper.MicroLogMsg(ob);
Response.ContentType = "application/json";
Response.Write(ob);
Response.End();
}
return null;
}
I hope this helps out anyone doing an MVC3 implementation for Facebook Credits.
i made an application that allow me to open conversation between friends, when someone send me a message i got a notification "John send you a new message" and when another person in the conversation send me a message a new notification is made ,,, my problem is that i don't want to make a new notification but i want to update the old notification to be for ex. like this " John and Alfred send you a new message"..
var user = users.Where(x => x != CurrentUserId);
foreach (var item in user)
{
var check = entities.Notifications.SingleOrDefault(i => (i.NotificationForId == id
&& i.NotificationForType == IdType && i.UserId == item));
if (check == null)
{
Notification notify = new Notification()
{
NotificationForId = id,
NotificationForType = IdType,
DateTime = DateTime.Now,
Message = GenerateMessage(),
UserId = item,
SenderID = CurrentUserId.ToString(),
SenderName = CurrentUserName
};
entities.Notifications.AddObject(notify);
}
else
{
check.Checked = false;
check.DateTime = DateTime.Now;
}
here it check if there are any notification for a user , if null then make a new notification else " Update the notification "
Your else block indicates the notification exists on the database, you can update the properties there. To save the changes made, both for insert and update call the method entities.SaveChanges()