Select field from SQL Datasource in Google App Maker based on drop down value - google-app-maker

I am running into an issue where I have 3 SQL Datasources (Employee, Course, Overview).
I have created a page inherited from the Overview Datasource, where i have created a drop down (options based on the Employee Datasource Employee.items.Name._equals, value set to Overview.Item.Name). When i select his name in the drop down, I want to dynamically fill in a text field where it selects the email field from the Employee Datasource based on the person selection in the drop-down.
Is this possible? If so, how do I proceed? If further information is required please feel free to ask.

Based on your comment change the following items around.
Overview Datasource dropdown options:
#datasources.Employee.items
Leave your dropdown value the same for now.
Dropdown onValueChange event:
widget.root.descendants.EmailTextBox.value = newValue.Email;
Observe that the newValue is a built in variable in the widgets API for a dropdown and points to an object of the options datasource, therefore, if your options are #datasources.Employee.items the options are an array of objects that make up all the Employee items and when selecting one option it points to items[index] and then you are able to call your object at index with the name of your object item. So newValue.Email should get the selected Employee email.

Related

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.
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.

Pre-select dropdown in a popup

I have an application that manages events. For every event several rooms can be booked. Hence I created tables for EVENTS, for ROOMS and for ROOM_BOOKINGS.
EVENTS has a one-to-many relation with ROOM_BOOKINGS which itself has a many-to-one relation with ROOMS.
Now I would like to trigger a pop-up from the event details page to create a new room booking for the event. Using the form generator I get a dropdown for the event the room binding should be tied to.
I would like to set this dropdown in form for a new room booking to the event that is shown on the current event details page and disable editing by the user.
I tried to set the options of the dropdown using the button that triggers the popup:
app.popups.AddRoomBooking.visible = true;
var currentEvent = [widget.datasource.item];
app.popups.AddRoomBooking.descendants.roomsbookedField.options = currentEvent;
But this not only feels weird, it also doesn't work, returning:
Fri Jul 06 12:18:10 GMT+200 2018 Expected List to match
List. at
EventDetailPage.roomBookingPanel.room_bookings_table.addRoomBooking.onClick:4:64
I guess the fundamental problem is that I do not understand what needs to be passed to a dropdown if it should represent a many-to-one relation.
I think the best thing to do is to bind the dropdown value to your datasource field you want it to update, and then your script should set the value on the datasource, and from there the dropdown will show the datasource value.
So for example if dropdown had options A, B or C, and the dropdown VALUE was bound to a create datasource relation field X, then the script would be:
CreateDatasource.item.fieldX = widget.datasource.item
(or if the relation field is many, then CreateDatasource.item.fieldX.push(widget.datasource.item).

Return value of another field within model

I have a model with two fields, Name and Token. In my app, the user will select a record from a Dropdown populated with the Name field of all records. When this happens, I need to assign the record's corresponding Token value to a variable in a server script, but am not sure how to accomplish this.
There are two options that are suitable. As a first option you could implement a server script that returns the token of the field when you edit the widget.
function checkToken(widgetValue) {
var query = app.models.YourModel.newQuery();
query.filters.Field._equals = widgetValue;
var records = query.run();
return records[0].Token;
}
You can add the script caller checkToken(widget.value) to the onValueEdit event of widget, so that it runs every time you select another dropdown item. If you want to use another event, please look at https://developers.google.com/appmaker/ui/logic#events.
As a second option you could add a secondary label to your form which you bind to the dropdown item selection. The binding would look something like this:
#pages.MyPage.descendants.DropDown.value.Token
When you configure Dropdown you need to set three important properties:
options
An array of string representations of options that makes up the content of the dropdown
#datasources.MyDatasource.items..Token
names
An array of strings to be displayed in place of options' default strings. The array must be the same length as options.
#datasources.MyDatasource.items..Name
value
The value assigned to the databound property, based on the user's dropdown selection
// Assuming that dropdown is added to form
// or any other container bound to proper datasource.
#datasource.item.Token
Note
double dot .. syntax is used for projections

How to show all items in Listbox that is linked to dropdown

In an Access Userform I have a listbox that is linked to a dropdown field. In the dropdown field the user can choose a country, and the listbox then updates and shows only the records that are relevant to that country.
I have described how I get the listbox to filter based on the selection in the dropdown in this question here.
While I managed to solve one problem there I created another.
Now when I open the form, the listbox is empty instead of showing all records.
My question: How can I show all records in the listbox to begin with and THEN have the user filter the list based on the dropdown?
The SQL Code in the LIstbox is now the following:
SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblISIN_Country_Table.Country
FROM tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN
GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblISIN_Country_Table.Country, tblFUNDS.Fund_Selection
HAVING (((tblISIN_Country_Table.Country)=[Forms]![frmMain]![ddnCountry].[Text]) AND ((tblFUNDS.Fund_Selection)=0));
So I ended up solving this one as well... with a bit of help from an online article which I can now no longer find unfortunately (otherwise I would reference it here):
SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblISIN_Country_Table.Country
FROM tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN
GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblISIN_Country_Table.Country, tblFUNDS.Fund_Selection
HAVING (((tblISIN_Country_Table.Country) Like Nz([Forms]![frmMain]![ddnCountry].[Text],'*')) AND ((tblFUNDS.Fund_Selection)=0));
The important part is this...
Like Nz([Forms]![frmMain]![ddnCountry].[Text],'*')) AND ((tblFUNDS.Fund_Selection)=0));
Essentially the Nz function lets you return a value when a variant is null. I had it return * which ofcourse is the SQL equivalent of Return All.

Populate a value in combobox dynamicly

I have a form where user picks a Item# and gets info for the selected Item. This form got enhanced by adding another filter, using a combobox control, to select a 'warehouse'.
I could use a lookup for the warehouse(the list is huge) to chosse a 'warehouse' but what am trying to do to query warehouse on Item# value and populate into combobox.
Tried to attached a screen shot, unfotunately, the system doesn't let me do it. If I need to put more details, please let me know.
Is it doable?
I would suggest you to do this with a temporary table. Create one in AOT, and declare it as global variable in your form.
When Item (datasource field or design control, choose what's more accurate for you) is modified, just delete table content, and fill it at your needs.
In the control lookup method, call temporary table lookup method, i.e. "static void lookup(TMPTable _tmpTable)". Do a SysTableLookup, with a standard query over TMPtable, but it's important to use QueryBuildDataSource.setCursor(_tmpTable) (I don't remember now where was method setCursor() in Query or QueryRun, search for it a bit).

Resources