Removing a Person Associated With a To-Do Item

We are now going to look at how to remove an association between a person and a to-do item.

Removing a Person from a To-Do Item

In the UI there is a little circle with an "x" in it that is used to remove a person from a task. Clicking this icon calls the uiRemovePersonFromToDo handler in the card script.

Update the uiRemovePersonFromToDo Command

Replace the empty uiRemovePersonFromTodo 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 uiRemovePersonFromTodo pPersonID

## Get selected to-do database id

put the uSelectedID of group "ToDo" into theToDoID

## Create SQL Record objects for person and to-do

put sqlrecord_createObject("people") into thePersonA

put sqlrecord_createObject("todo_items") into theToDoA

## Just set the fields that are used to link records together

sqlrecord_set thePersonA, "id", pPersonID

sqlrecord_set theToDoA, "id", theToDoID

sqlrecord_unlink thePersonA, theToDoA

put the result into theError

if theError is empty then

## Refresh list

RefreshToDoList

end if

if theError is not empty then

answer "Error removing person from to-do item:" && theError & "."

end if

end uiRemovePersonFromTodo

Removing the Link Between Two Database Records

Removing the associated between two records is just as easy as associating two records. The only difference is that you call sqlrecord_unlink rather than sqlrecord_link.

Since the only errors that can be thrown when deleting an existing record are ones we are interested in knowing about there is no need to wrap the call in a try/catch block like we did for sqlrecord_link.

Test the UI

Click on the "x" next to New Person to trigger the uiRemovePersonFromTodo command.

The to-do list will refresh and you will see that the to-do item is no longer associated with New Person.

Verify in the Database

If you look at the records in the people_todo table you will see that there are no longer any.

0 Comments

Add your comment

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