Update the UI Code to Account For People

Now that the left column displays both projects and people we will need to update the uiPopulateToDos handler accordingly. We will look at how the newly defined relationships can help us get to-do items associated with a person.

Update the uiPopulateToDos Command

Replace the uiPopulateToDos command in the card script with the following RevTalk code. After you insert the code we will go through the relevant parts.


Copy & Paste The Following Code


command uiPopulateToDos

local theRecordsA,theError

switch the uSelectedType of group "ProjectsPeople"

case "project"

put the uSelectedProjectID of group "ProjectsPeople" into theProjectID

put sqlquery_createObject("todo_items") into theQueryA

sqlquery_set theQueryA, "order by", "sequence"

sqlquery_set theQueryA, "conditions", "project_id is :1", theProjectID

sqlquery_retrieveAsRecords theQueryA, theRecordsA

put the result into theError


case "person"

put the uSelectedPersonID of group "ProjectsPeople" into thePersonID

put sqlquery_createObject("todo_items") into theQueryA

sqlquery_set theQueryA, "related table joins", "people"

sqlquery_set theQueryA, "conditions", "people.id is :1", thePersonID

sqlquery_retrieveAsRecords theQueryA, theRecordsA

put the result into theError


end switch

if theError is empty then

set the dgData of group "ToDo" to theRecordsA

end if

if theError is not empty then

answer "Error populating to-do items:" && theError & "."

end if

end uiPopulateToDos

Getting To-Do Items Related To Selected Person

You are looking at the modified code for uiPopulateToDos. Notice that the code now branches based on whether a person or project is selected (1).

What is interesting about the new code for retrieving to-do items is the use of the related table joins property (2). Remember that we told SQL Yoga that 'people' are related to 'todo_items'. By telling the SQL Query object that the query should include 'people' SQL Yoga will automatically add the necessary SQL to include the 'people' table in the query. This allows us to use 'people.id' in the 'conditions' property (3) to filter which to-do items are returned. Basically the query searches for all to-do items that are associated with the selected person.



Click on New Person in the left column. You should see an empty list on the right. If you select New Project on the left then the New Task record should appear in the list.


David Glass

I must have missed a step somewhere.

Where does the type ('project' or 'person') of the selection in the left-hand 'source list' get set (uSelectedType)?

I didn't see anything explicitly setting that value when the list was populated.

Trevor DeVore

David - the uSelectedType is a custom property that is defined in the group "ProjectsPeople" script. If you edit the group script you will see this handler:

getProp uSelectedType
end uSelectedType

This getProp handler returns the type of record that is currently selected in the data grid "ProjectsPeople".

David Glass

And 'getProp' is called any time the property's name is used?

So the 'switch the uSelectedType' kicks out to the 'getProp'?

Trevor DeVore

Correct. If you aren't familiar with getProp handlers then I would recommend reading up on it in the docs: http://docs.runrev.com/Control-Structure/getProp. It basically lets you execute code when setting a custom property on an object.

Add your comment

E-Mail me when someone replies to this comment

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