Display Projects in the UI

Now that we have a way of creating a new project using the UI we need to be able to display them. Let's look at how to do that.

What We Are Going To Do

Now we are going to add the RevTalk code that will display projects from the database in the UI.

Update uiPopulateProjectsAndPeople Handler

Begin by replacing the existing uiPopulateProjectsAndPeople handler in the card script with the RevTalk code below. Remember to compile the script. After you insert the code we will go through the relevant parts.

----------

Copy & Paste The Following Code

----------

command uiPopulateProjectsAndPeople

## Create a SQL Query object

put sqlquery_createObject("projects") into theQueryA

## Specify how results should be sorted

sqlquery_set theQueryA, "order by", "name"

## Retrieve data from database and convert to

## a numerically indexed array

sqlquery_retrieveAsRecords theQueryA, theDataA

put the result into theError

if theError is empty then

## Assign the array directly to a Data Grid

set the dgData of group "ProjectsPeople" to theDataA

end if

if theError is not empty then

answer "Error populating projects and people:" && theError & "."

end if

end uiPopulateProjectsAndPeople

Using a SQL Query Object to Retrieve Data

We are going to retrieve projects from the database using a SQL Query object. A SQL Query object is similar to a SQL Record object in that it is represented by an array variable. It does not persist across sessions. Here is how you can get an array variable that contains a list of projects and display the list in a Data Grid:

1) Create a SQL Query object for the projects table.

2) Specify how you would like the projects sorted by setting the sort by property.

3) Tell SQL Yoga to retrieve the projects from the database and convert the result to a numerically indexed array of SQL Record objects.

4) Assign the array returned by SQL Yoga to the ProjectsPeople Data Grid. This Data Grid has already been configured for displaying the content.

Test

To test, open the Message Box and type in uiPopulateProjectsAndPeople (1) and press the Return key. You should see the text New Project appear in the Data Grid (2).

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.