Search code examples
google-app-maker

Using popup to select correct relational field and pass value back to an entry form


I am using Google App Maker with Cloud SQL to build an asset tracking database. I have a couple tables with relations:

  • Asset List (Many to One with locations)
  • Locations (Many to One with Districts)
  • Districts (Many to One with Areas)

The issues is when populating new related location fields in an data entry form is that several districts may have locations with the same name. When using the standard drop down the same values appear and there is no way for the user to know which district the location is associated with. Example: On the asset entry form drop down locations show:

- Shop
- Crew 1
- Crew 2
- Shop
- Crew 1
- External Vendor

I have 2 pages:
Assets - Datasource: Assets table

  • Entry form Datasource:inherited(assets) to enter new assets
  • Table View Datasource:Inherited(assets) to see asset that get entered )no edit)

Locations Pop-up
This seems to work as expected basically forms to navigate to correct Location and store it in a text box and a button with the On_Click property to send the textbox value to the data entry form on assets (not working) I can pass the value to a widget but can't figure out how to save it to the actual data source. Currently using the location in the text box on this form should i be using Id?

I created a pop-up form which lets the user navigate to the correct location record ID by filtering on district. I am having trouble understanding how to actually write it back to the correct location field on the asset entry form. I am new to Java Script/Apps Script so the meaning of all the properties and how to use them is giving me trouble.

I tried setting a text box named SetLocation in the entry form and setting the value property to

@datasource.item.Location.Location

Then in the popup I set the button on_click to

app.pages.Assets.descendants.SetLocation.value = 
widget.parent.descendants.PassLocation.value;

Pass Location is the name of the textbox on the popup where the correct location is stored.


Solution

  • Some suggestions to consider. In your popup set a dynamic property, call it 'CreateDatasource' or whatever suits your needs.

    In your assets page form where you navigate to your popup (lets say it's a button that opens the popup from your form) put the following code:

    var popup = app.popups.YourPopup;
    popup.properties.CreateDatasource = widget.datasource;
    popup.visible = true;
    

    Lets say your popup content datasource is set to Locations, and your popup has some inputs that filter your locations and then there is a table that displays your filtered results. In this table you would select the appropriate location row and then your popup has a button that passes the location back to your asset form, with code like this:

    widget.root.properties.CreateDatasource.item.Location = widget.datasource.item; //this would set the relation only assuming your asset relation end to locations is named 'Location'
    widget.root.visible = false;
    

    This would work assuming everything is set up correctly in your relations.