Search code examples
google-app-maker

In App Maker, can you fake valueIsRecord with a dropdown field?


In App Maker, what is the simplest way to achieve the same result with a dropdown box that you can with a suggest box, which can return the whole record when you make a selection giving you the ability to assign associated record values to other fields on the page?

Consider a data model with three fields, (Code, Description, and Severity). Add a dropdown box to select the Code. Have the selection, (probably using onValueChange or onValueEdit), write the selected Code's Description to a label field beside the dropdown box. The Code's Severity will also be used to affect the style in some way like background color or something, but for this answer, merely assigning the value to a scripting variable will be good enough. It's the record value access and assignment mechanism I am after.

Clarification: This data model will not be the page's datasource. It is a secondary reference table used for assigning a code to a ticket. You can also assume that a record value will be written to a field in the page's datasource as well.

I would appreciate the simplest low code solution as we will have non-programmers attempting this. Thanks.


Solution

  • As long as you leave your value binding on the dropdown blank the following should work:

    Set the options binding to:

    @datasources.YourDatasource.items
    

    You may want to consider changing the 'Names' binding to be the projection of a particular field in this datasource otherwise the values showing in your dropdown will only be the 'keys' from this datasource.

    Then in your onValueEdit event you will gain access to individual fields like this:

    var item = widget.datasource.item;
    item.YourFieldToEdit1 = newValue.YourOtherDatasourceField1;
    item.YourFieldToEdit2 = newValue.YourOtherDatasourceField2;
    

    That would probably be the simplest way.