Q:

Recording Phone Number and Full Name in Project Datasource

I have implemented a user picker into my app in google app maker and synced up the Directory.  It works when I use it and stores the email address into the Project datasource I have setup, but I also want to record the associated PrimaryPhone and FullName of the email address as seperate variables within my project database.  I do not know if this will be code within a script or within the datasource onCreate or onLoad.  Any help on this issue would be greatly appreciated.  

A:

If you are concerned about security and data consistency, then you can go with server side implementation:
// onCreate model event handler (takes about-to-create record as parameter)
var query = app.models. Directory.newQuery();

// assuming that email field value is populated by UserPicker widget on client-side
query.filters. PrimaryEmail._equals = record. Email;
var people = query.run();

if (people.length === 1) {
  var person = people[0];

  record. FullName = person. FullName;
  record. PrimaryPhone = person. PrimaryPhone;
} else {
  // TODO: handle edge cases
}

If you are not paranoiac about security, you can:

Configure UserPicker to select entire object (check 'valueIsRecord' property checkbox). 
Handle onValueEdit UserPicker widget event:

// onValueEdit UserPicker event
// assuming that widget is bound to datasource's create mode item
var draft = widget.datasource.item;

draft. Email = newValue. PrimaryEmail;
draft. FullName = newValue. FullName;
draft. PrimaryPhone = newValue. PrimaryPhone;

