Search code examples
google-app-maker

Appmaker - Relation between local datasource and external datasource/Directory


Trying to make a relational join between a local source (MyStaff) and the external datasource Directory (my company's directory).

However, there isn't an option to relate them.

Was hoping to create a local datasource with custom fields that I can "append" to user records from the existing Directory datasource.

Any help is appreciated.

L.


Solution

  • There is no way to create relations between Directory Model and other model types. You have at least three ways to workaround this shortage:

    One

    Query directory records on the fly - this will okish work for single-record pages, but it will be tooo slow for lists.

    Two

    You can duplicate Directory fields you need in your tables.

    Pros:

    • it will NOT slow down your app
    • it will let you to implement queries with mixed models data (Directory + Drive Tables or Cloud SQL)

    Cons:

    • You will store same data in two different places
    • Eventually your version of Directory data will become stale

    You can find nice sample of the second approach in People Skills app.

    Three

    Query Directory data on demand. Let's say you have databound list, and records bound to the list have UserEmail field. In this case you can:

    1. Add some button to the list row
    2. In button onClick event handler add code similar to this:
    app.datasources.Directory.query.filters.PrimaryEmail._equals = widget.datasource.item.UserEmail;
    app.datasources.Directory.load();
    app.showPage(app.pages.UserDetails); // or app.showDialog(app.pages.UserDetails);