Generating an email list from AppMaker Database

2019-02-28 10:24发布

I am trying to figure out how I can get database information involving the email column, make an array with all of the emails and then use the "button" feature to populate the "To:" part of an email page.

Any help is appreciated. Very new at this and pointing me on where to get the info would be great. Thanks

2条回答
孤傲高冷的网名
2楼-- · 2019-02-28 11:01

I recommend you to run a server script that would query the datasource that has the emails. The script will look something like this:

function getEmails(){

  var query = app.models.<yourmodel>.newQuery();
  var results = query.run();

  var allEmails = [];

  if(results.length > 0){  
    for(var i = 0; i < results.length; i++){    
      var uniqueEmail = results[i].<emailfieldname>;
      allEmails.push(uniqueEmail);      
    }
  }

  return allEmails.join();      

}

Then add a scrip to the button widget "onclick" event that will run the server script and manipulate the returned data. Something similar to this:

function poulateToField(response){

  <widget path>.text/value = response;

}

google.script.run.withSuccessHandler(poulateToField).getEmails();

The above widget path would be the path to the "To:" widget, which can be a text box, text area, etc. In my case, I used a text area and the path was this "widget.parent.descendants.TextArea1.value"

I hope this helps. If you have more questions, just let me know! :)

P.D. Please don't forget to review the official documentation for a better and more detailed explanation.

查看更多
Juvenile、少年°
3楼-- · 2019-02-28 11:18

you can also use projections to get a list of items (emails) from your datasource. As per this Article https://developers.google.com/appmaker/ui/binding#projections:

Projections let you access properties from records in a datasource's items list. Access projections with the ..projections.. option in the advanced binding wizard, or use the projection operator .. in a binding path. For example, for an Employees datasource with a name property, @datasources.Employee.items..name returns a list of all employees' names.

You can check the "Call Scripts" guide which shows you how to send emails using App Maker which is available here https://developers.google.com/appmaker/tutorials/call-scripts/

To use projections and following the above guide, in Step #2 under "Create the UI": Add a text box for the recipient:

c. In the Property Editor, instead of entering the "To" value to the Textbox widget, you can select Binding and bind the widget to the Datasource projections following this path: datasource > items > ..projections.. > Email (name of the datasource field where the emails are located)

For example a projection will look like this: @datasource.items..email

This will automatically bind all emails that are available in your datasource to the text box widget. Then you can complete the guide and emails will be sent to all the email addresses in your datasource. Hope this helps.

查看更多
登录 后发表回答