Create Data View from a query with a parameter

Hello FIVE team,

Please explain how to create a Data View that is sourced from a query with a parameter that has to be selected in a drop-down list on this Data View.

My query (DealsAndCommissionsPerUserQuery):

SELECT
Users.UserName as “UserName”,
Deals.DealName as “DealName”,
DealStatus.DealStatus as “DealStatus”,
CONCAT(‘$’, FORMAT(UserCommissions.UserCommissionAmount, 0)) as “UserCommission”
FROM
Users
INNER JOIN
UserCommissions ON Users.UsersKey = UserCommissions.UsersKey
INNER JOIN
Deals ON UserCommissions.DealsKey = Deals.DealsKey
INNER JOIN
DealStatus ON Deals.DealStatusKey = DealStatus.DealStatusKey
WHERE
UserName = ?;

I need to be able to choose a user in the drop-down list, pass the selected User Name to the UserName parameter in my Query, and then get the query results based on the selected User Name.

Attached is my database schema.

Please describe the process step-by-step.

Also, is it possible to simultaneously execute TWO queries with a single parameter selected in a single drop-down list on a Data View and/or on a Dashboard?

In other words, I need to create a Dashboard, on which I will have a User Name drop-down list sourced from the Users table. Once I select a user in the drop-down list, TWO queries should display results on that Dashboard, based on the selected User Name.

If it’s possible, please provide step-by-step instructions on how to do it.

If you need more details, please let me know.

Thank You very much!

Regards,

Vlad T.

Hello Vladt,

I have attached an fdf that demonstrates these two questions. In the menu called ‘DataView’, is a data view that updates depending on which user has been selected, in the menu called ‘DashBoard’ is a dashboard consisting of two data views in which are both updates when a user is selected in the search bar above them.

QUESION 1 → Single Data View

Within the query you are using for the Data View, you will need to add a parameter.

In this image, the added parameter is ‘userkey’. The value placed in this parameter is the value which fills in the placeholder value (?) in your query. The name of this parameter ({{five.variable.NAME}}) must match with the corresponding database field.

Within your Data View, this query is then added to the Data Source field.

In Screen Fields, you will then need to add a field in which is used to acquire the user key from a dropdown menu.

In my example, I have used a look up query so that the user’s names are displayed within the dropdown menu. When a user is selected from this dropdown, the user key for that user will be passed into the initial query, the Data View will then display the data related to this user key.

QUESTION 2 → Dashboard
After creating a dashboard, you will need to adjust the rows to be 2 and the columns to be 2.

This will allow for a search feature to be added at the top, and then two Data Views to be added at the bottom.

Next, you will need to create a process. These can be created under the ‘Tasks’ tab in the five navbar.

Within this process, you will need to attach a query to acquire a user key (or database key value you wish to grab). In my example, I have used the same lookup query from before to look up the users and display their names in the dropdown menu.

Within your two queries used within the two Data Views, you will also need to add the corresponding parameters (like we did in the single Data View).

Within the Dashboard, add the process in the top row (A1), and the two Data Views in the bottom row (B1), (B2).

Finally, you will need to create a function in order to refresh these Data Views when selecting an item from the dropdown menu.

To do so, go to Logic > Functions > Add Function (+ button)

This is the function used in my example. For info on the refreshTable() function in Five, head to refreshTable() | Five | Low-Code For Real Developers . For info on the setVariable() function, head to setVariable() | Five | Low-Code For Real Developers .

Save this function and head back to the processes tab. You will now need to attach this function to the process you previously created.

  1. Click the process and click screen fields
  2. Click into the screen field you created
  3. Click events
  4. Attach the function to the ‘On List Select’ event

Now, the two Data Views will update when selecting an item from the dropdown menu (the process).

I have attached the fdf containing the example I have shown below so you can see it and follow through with the steps.

DataViewQuery-20240805-063948311253514.fdf (3.4 MB)

Please let me know if you have any more questions,

Thanks,
Riley.

1 Like

Hi Riley,

Thank you for the detailed explanations! I precisely followed your guidance, but unfortunately, the functionality is not working yet.

I downloaded the application you provided and deployed it on the local version of Five installed on my computer. The app returned empty results (the User Name drop-down lists were empty) and an error (see screenshots attached.)



Now here is what I did on my side.

  1. Created a query named ‘UserNameQuery’ to feed the User Name drop-down list:

  2. Created a parameterized query named ‘DealsAndCommissionsByUserQuery’ to be displayed on the Data View:

The DealsAndCommissionsByUserQuery is set Live, it has a parameter:

  1. Created a Data View named ‘DealsAndCommissionsByUser’ sourced by the DealsAndCommissionsByUserQuery:

with the following Data Fields and Screen Field:


The result I got is as follows: The User Name list is populated with proper data, but no results are produced. (no errors either).

When I tried to substitute the “?” in the DealsAndCommissionsByUserQuery with one of the actual names, the results were returned on the application for this person. Therefore, I assume the User Name is not being passed from the User Name drop-down list to the DealsAndCommissionsByUserQuery.

Please help to make it work.

Thank You!

Vlad T.

DataViewQuery-2.6a.fdf (3.4 MB)

Hi vladt,

You are experiencing this because Riley has developed the example app in a newer version of Five, the app has now been imported into the version you are using and the changes have been made to support your version.

Could you please, export your app and back it up (just in case you have made changes you want to keep) and then delete the app out of Five and import the one attached. You need to delete the current one you have because these apps have the same database ID and you will not be able to have them both in Five at the same time.

After this, you can follow Riley’s steps again.

Let us know if you need further assistance.

Kind regards,

Jo

1 Like

Hi Jo,

Your program now works, but mine still doesn’t!

Speaking of your program, I didn’t find any difference between the two versions that you sent me. Therefore, I don’t even know what to change in my program to make it work. Initially, I replicated the steps that were provided to me.
What do I do to make it work?

Thank You

Vlad

Hi vladt,

There were only a few settings that needed to be changed between the two versions and this was due to the app being built in a newer version and then being imported into an older version. So you wouldn’t of noticed any difference in the application and normally this would not of even needed to be performed.

In regards to your application, in your DealsAndCommissionsByUserQuery could you change your WHERE condition from:

UserName = ?

to

UsersKey = ?

Can you please run it and test it again and that should work for you.

Please let me know how you go!

Kind regards,
Jo

1 Like

Thank You, Jo! That did the trick! Next, I’ll work on the Dashboard.
Hopefully, it will work.

Thank you!

Vlad

Jo,

Is it possible to make some data (not all) inside the query results clickable links?

For example, if I click on any Deal Name, I want to be redirected to the corresponding Deal’s form, such as this:

Is it possible to do it? If so, please explain how.

Thank You!

Vlad

Hello Vladt,

Sorry for the late reply!

This is a simple fix, I have attached an fdf with an example on how to do this.

First, I created a JavaScript function in which will select the actionID of the desired form when the Data View button is clicked.

I then attached this function to a field within the Data View (I attached in to the FirstName field in my example). Now, when the FirstName field within the Data View is clicked, it will bring up the corresponding entry in the selected form.

Note: It brings up the corresponding entry via passing the ‘CustomerKey’ value into selectAction function within the JavaScript function attached to the Data View Field.

VladtDataview-20240812-0147224871712.fdf (2.9 MB)

Hopefully this helps!

Let me know if you have anymore questions,
Thanks,
Riley.

1 Like

Thank you so much for the instructions, Riley!

Hello,

Just one more thing to add onto this. In my example, I attached it to a database field within the Data View, however, you are also able to add another column in the Data View that consists of buttons, when you can name them something like ‘View Record’ so its a bit more clear to the user.

To do this, you add another field in your data view and leave the ‘Field’ input blank. You then give it a caption, field ID, and then set the display type to button. Then attach the Javascript function to this button field instead.

Thanks,
Riley.

1 Like

Hi Riley,

That works, thank you!

Is there any way to:

  1. Remove the header from the links column (highlighted in red)?

  2. Make the links (highlighted in yellow) not all-caps?

Thank you!

Vlad

Hi Vlad,

you can remove the header by replacing the “Edit Deal” caption with an empty character, such as this Empty Characters, Whitespaces & Blank Unicode Characters

The capitalization of EDIT DEAL cannot be changed, unfortunately.

Best

Dom

Hi Dom,

Thank you for the reply. I tried to replace the caption with an empty character, but it makes the whole column of buttons empty. The Caption field regulates both the header of the buttons column and the names of all the buttons in that column.

It would be great if there were a way to edit the column header and the names of the buttons in the buttons column separately.

Regards,

Vlad

Hi Vlad,

My apologies, you are right. Putting an empty character into the caption only works when the column in the data view is not a button, but a list of records. With a button, the caption applies to the column header and the in-button text.

We will take your feedback onboard to separate these!

Best

Dom