0
votes

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 = "[email protected]";
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);
}
1

1 Answers

2
votes

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;